Md5¶
| Spice | |
|---|---|
Md5 struct¶
MD5 message digest, as specified in RFC 1321.
MD5 is considered cryptographically broken: practical collisions can be produced within seconds. It is provided for interoperability with existing formats and protocols (checksums, legacy file digests, ETags) only. Never use it for signatures, password storage or any other security decision - reach for std/crypto/sha256 instead.
The digest is computed incrementally, so arbitrarily large messages can be fed in chunk by chunk:
spice Md5 hasher; hasher.update("Hello, "); hasher.update("World!"); printf("%s\n", hasher.finalize().getRaw()); // 65a8e27d8879283831b664bd8b7f0ad4
For one-shot use, the free md5 functions wrap the same steps in a single call.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a hasher that is ready to consume the first message byte
Methods¶
reset¶
| Spice | |
|---|---|
Discard any consumed input and return to the initial state, ready for a new message
update¶
| Spice | |
|---|---|
Feed the given raw bytes into the digest
Parameters
| Name | Type | Description |
|---|---|---|
data |
const byte[] |
Bytes to consume |
length |
unsigned long |
Number of bytes to consume |
update¶
| Spice | |
|---|---|
Feed the chars of the given raw string into the digest, excluding the null terminator
Parameters
| Name | Type | Description |
|---|---|---|
data |
string |
String to consume |
update¶
| Spice | |
|---|---|
Feed the chars of the given string into the digest
Parameters
| Name | Type | Description |
|---|---|---|
data |
const String& |
String to consume |
finalizeInto¶
| Spice | |
|---|---|
Complete the digest and write its 16 raw bytes to the given output array. The hasher is reset afterwards, so it can be reused for the next message.
Parameters
| Name | Type | Description |
|---|---|---|
digest |
byte[] |
Output array, that has to offer room for at least 16 bytes |
finalize¶
| Spice | |
|---|---|
Complete the digest and return it as a lowercase hex string. The hasher is reset afterwards, so it can be reused for the next message.
Returns: String — Digest as 32 lowercase hex chars
getDigestSize¶
| Spice | |
|---|---|
Retrieve the number of bytes an MD5 digest occupies
Returns: unsigned long — Digest size in bytes
getBlockSize¶
| Spice | |
|---|---|
Retrieve the number of bytes MD5 consumes per compression step
Returns: unsigned long — Block size in bytes
Functions¶
md5¶
| Spice | |
|---|---|
Compute the MD5 digest of the given raw string
Parameters
| Name | Type | Description |
|---|---|---|
input |
string |
String to hash |
Returns: String — Digest as 32 lowercase hex chars
md5¶
| Spice | |
|---|---|
Compute the MD5 digest of the given string
Parameters
| Name | Type | Description |
|---|---|---|
input |
const String& |
String to hash |
Returns: String — Digest as 32 lowercase hex chars
md5¶
| Spice | |
|---|---|
Compute the MD5 digest of the given raw bytes
Parameters
| Name | Type | Description |
|---|---|---|
input |
const byte[] |
Bytes to hash |
length |
unsigned long |
Number of bytes to hash |
Returns: String — Digest as 32 lowercase hex chars