Method: OpenSSL::HMAC#digest

Defined in:
ossl_hmac.c

#digestString

Returns the authentication code an instance represents as a binary string.

Example

instance = OpenSSL::HMAC.new(‘key’, ‘SHA1’) #=> f42bb0eeb018ebbd4597ae7213711ec60760843f instance.digest #=> “xF4+xB0xEExB0x18xEBxBDEx97xAErx13qx1ExC6a‘x84?”

Returns:

  • (String)


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'ossl_hmac.c', line 182

static VALUE
ossl_hmac_digest(VALUE self)
{
    EVP_MD_CTX *ctx;
    size_t buf_len = EVP_MAX_MD_SIZE;
    VALUE ret;

    GetHMAC(self, ctx);
    ret = rb_str_new(NULL, EVP_MAX_MD_SIZE);
    if (EVP_DigestSignFinal(ctx, (unsigned char *)RSTRING_PTR(ret),
                            &buf_len) != 1)
        ossl_raise(eHMACError, "EVP_DigestSignFinal");
    rb_str_set_len(ret, (long)buf_len);

    return ret;
}