Skip to main content

Python interface for librhash

Project description

RHash

RHash is a Python library for computing various message digests, including CRC32, CRC32C, MD4, MD5, SHA1, SHA2, SHA3, AICH, ED2K, DC++ TTH, Tiger, BitTorrent BTIH, GOST R 34.11-94, GOST R 34.11-2012, RIPEMD-160, HAS-160, BLAKE2s, BLAKE2b, EDON-R, and Whirlpool.

Installation

RHash requires LibRHash library. The LibRHash sources or Windows binaries can be downloaded from:

Linux and BSD users should install LibRHash from the official repository.

To build LibRHash from sources use commands

$ ./configure
$ make lib-shared install-lib-shared

In order to be loaded by RHash Python module, the LibRHash library should be placed in the appropriate directory or you can change required environment variable.

To install the RHash Python module use the package manager pip

$ pip install rhash-Rhash

You can also build the module from source

$ python3 -m build

Usage

Hashing a file or a text message can be done using RHash hi-level interface

>>> import rhash
>>> rhash.hash_file("input-file.txt", rhash.SHA3_256)
'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a'
>>> rhash.make_magnet("input-file.txt", rhash.CRC32, rhash.TTH)
'magnet:?xl=0&dn=input-file.txt&xt=urn:crc32:00000000&xt=urn:tree:tiger:lwpnacqdbzryxw3vhjvcj64qbznghohhhzwclnq'
>>> message_digest = rhash.hash_msg("abc", rhash.SHA1)
>>> print("SHA1 (\"abc\") = {}".format(message_digest))
SHA1 ("abc") = a9993e364706816aba3e25717850c26c9cd0d89d

The Low-level interface allows to calculate several message digests at once and output them in different formats

>>> import rhash
>>> h = rhash.RHash(rhash.MD5, rhash.SHA1, rhash.BLAKE2S)
>>> h.update("abc")
<rhash.rhash.RHash object at 0x7fc512d90670>
>>> h.finish()
<rhash.rhash.RHash object at 0x7fc512d90670>
>>> h.hex(rhash.MD5)
'900150983cd24fb0d6963f7d28e17f72'
>>> h.hex_upper(rhash.MD5)
'900150983CD24FB0D6963F7D28E17F72'
>>> h.base32(rhash.SHA1)
'vgmt4nsha2awvor6evyxqugcnsonbwe5'
>>> h.base32_upper(rhash.SHA1)
'VGMT4NSHA2AWVOR6EVYXQUGCNSONBWE5'
>>> h.base64(rhash.BLAKE2S)
'UIxejDJ8FOLhpyujTutFLzdFiyCe1jopTZmbTIZnWYI='

The RHash object can be used within the with operator

import rhash
with rhash.RHash(rhash.MD5) as ctx:
    ctx.update("a").finish()
    print(ctx.hash(rhash.MD5))

Contribution

To contribute to the project, please read the Contribution guidelines document.

License

The code is distributed under the BSD Zero Clause License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rhash_rhash-1.2.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

rhash_Rhash-1.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file rhash_rhash-1.2.tar.gz.

File metadata

  • Download URL: rhash_rhash-1.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for rhash_rhash-1.2.tar.gz
Algorithm Hash digest
SHA256 5f68aef6cb8efc99117d1edb17c88e139c234fb038edcbe5a59923817985de06
MD5 c9555eb51916afeec5061794e7fc32dc
BLAKE2b-256 79f02eb323426e1e580f6907e155d00b501cec54fd8f667e13b18f2f5f74199c

See more details on using hashes here.

File details

Details for the file rhash_Rhash-1.2-py3-none-any.whl.

File metadata

  • Download URL: rhash_Rhash-1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for rhash_Rhash-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 08095231fd899821bcd2b4d7dbe6e06399ffd0930060be8f1393855d9ebefef7
MD5 1e6aec0067b46ece0d8752d5eed5bab7
BLAKE2b-256 66676cc9ade565fb31a27a1a8e324318cce93cb967b2de3e9b3a927029267f68

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page