module MbedTLS::DigestBase

Overview

Describes common utility methods for working with message digests.

Direct including types

Defined in:

digest/digest_base.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.hexdump(digest) #

Utility method, converts a buffer slice to a hexadecimal representation.


[View source]

Instance Method Detail

def <<(data) #

Shorthand operator for #update. You can chain the << operator to concatenate data into the internal buffer of the Digest instance for hashing.

require "mbedtls"
digest = MbedTLS::Digest::SHA256.new
digest << "Hello, world"
puts "SHA256(Hello, world) = #{digest}"

Output:

SHA256(Hello, world) = 4ae7c3b6ac0beff671efa8cf57386151c06e58ca53a78d83f36107316cec125f

[View source]
def base64digest #

Returns the Base64 encoded representation of the digest.


[View source]
def digest #

Hash the buffer and return the raw bytes returned by the digest algorithm.


[View source]
def file(file_name) #

Utility method to read a file into the internal buffer of the Digest instance.


[View source]
def hexdigest #

Returns the hexadecimal representation of the digest.


[View source]
def to_s(io) #

Converts digest instance to a string by creating it's hexadecimal representation.


[View source]
def update(io : IO) #

Adds the contents of the io I/O buffer to the internal buffer of the Digest instance. You can call #update until the buffer contains the full data for hashing; the contents of the buffer get appended with each call.


[View source]