Skip to content

Obtain hash output as a String #185

@jjpe

Description

@jjpe

Currently, this results in a value of GenericArray<u8, _>:

let input = String::from("hello");

let mut hasher = Sha512::new();
hasher.update(input);
let hash_result = hasher.finalize();

However, what I need is not a byte array but a String as output.
I tried converting it with std::str::from_utf8(&hash_result[..]) but that errors out with Err(Utf8Error { valid_up_to: 0, error_len: Some(1) }) as an error value. This seems weird to me since the hash should be a hexadecimal string, but that's what I observed.

How can I get a valid UTF-8 string from hash_result?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions