Struct openssl::hash::Hasher [] [src]

pub struct Hasher { /* fields omitted */ }

Provides message digest (hash) computation.

Examples

Calculate a hash in one go:

use openssl::hash::{hash, MessageDigest};

let data = b"\x42\xF4\x97\xE0";
let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
let res = hash(MessageDigest::md5(), data).unwrap();
assert_eq!(res, spec);

Supply the input in chunks:

use openssl::hash::{Hasher, MessageDigest};

let data = [b"\x42\xF4", b"\x97\xE0"];
let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
let mut h = Hasher::new(MessageDigest::md5()).unwrap();
h.update(data[0]).unwrap();
h.update(data[1]).unwrap();
let res = h.finish().unwrap();
assert_eq!(res, spec);

Warning

Don't actually use MD5 and SHA-1 hashes, they're not secure anymore.

Don't ever hash passwords, use the functions in the pkcs5 module or bcrypt/scrypt instead.

Methods

impl Hasher
[src]

[src]

Creates a new Hasher with the specified hash type.

[src]

Feeds data into the hasher.

[src]

Deprecated since 0.9.11

: use finish2 instead

[src]

Returns the hash of the data written and resets the hasher.

Unlike finish, this method does not allocate.

Trait Implementations

impl Write for Hasher
[src]

[src]

Write a buffer into this object, returning how many bytes were written. Read more

[src]

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

1.0.0
[src]

Attempts to write an entire buffer into this write. Read more

1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

impl Clone for Hasher
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Drop for Hasher
[src]

[src]

Executes the destructor for this type. Read more