File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1
1
require " ./lib_crypto"
2
2
3
+ # Allows computing Hash-based Message Authentication Code (HMAC).
4
+ #
5
+ # It is a type of message authentication code (MAC)
6
+ # involving a hash function in combination with a key.
7
+ #
8
+ # HMAC can be used to verify the integrity of a message as well as the authenticity.
9
+ #
10
+ # See also [RFC2104](https://tools.ietf.org/html/rfc2104.html).
3
11
class OpenSSL::HMAC
12
+ # Returns the HMAC digest of *data* using the secret *key*.
13
+ #
14
+ # It may contain non-ASCII bytes, including NUL bytes.
15
+ #
16
+ # *algorithm* is a `Symbol` of a supported digest algorithm:
17
+ # * `:md4`.
18
+ # * `:md5`.
19
+ # * `:ripemd160`.
20
+ # * `:sha1`.
21
+ # * `:sha224`.
22
+ # * `:sha256`.
23
+ # * `:sha384`.
24
+ # * `:sha512`.
4
25
def self.digest (algorithm : Symbol , key, data) : Bytes
5
26
evp = case algorithm
6
27
when :md4 then LibCrypto .evp_md4
@@ -20,6 +41,11 @@ class OpenSSL::HMAC
20
41
buffer[0 , buffer_len.to_i]
21
42
end
22
43
44
+ # Returns the HMAC digest of *data* using the secret *key*,
45
+ # formatted as a hexadecimal string. This is neccesary to safely transfer
46
+ # the digest where binary messages are not allowed.
47
+ #
48
+ # See also `#digest`.
23
49
def self.hexdigest (algorithm : Symbol , key, data) : String
24
50
digest(algorithm, key, data).hexstring
25
51
end
You can’t perform that action at this time.
0 commit comments