uhashlib-hash algorithm

This module implements a subset of the corresponding CPython module, as described below. For more information, please refer to the original CPython documentation: hashlib.

This module implements a hash algorithm for binary data. The exact list of available algorithms depends on the board. Among the algorithms that can be implemented:

The latest modern hash algorithm of the SHA256-SHA2 series. It is suitable for password security purposes. Unless it has a specific code size limit, it is recommended to include it in the MicroPython kernel, and it is recommended that any development board provides this feature.

There is hardware acceleration in K210, not software calculation


a = bytes([0]*65)
b = hashlib.sha256(a)
c = b.digest()


Class uhashlib.sha256([data])

Create a SHA256 hash object and selectively feed data into it.



Enter more binary data into the hash.


Returns the hash of all data passed through the hash as a bytes object. After calling this method, no more data can be fed into the hash.

Note: In micropython, using this function will complete the final calculation, instead of simply displaying the result, it can only be called once. If you want to use this value multiple times, please save it to a variable

c = b.digest()

Multiple calls will find that the return value is different

c = b.digest()
d = b.digest()
print(c == d) # False


This method is not implemented. Use ubinascii.hexlify(hash.digest()) to get a similar effect.