Method: OpenSSL::HMAC#hexdigest

Defined in:
ossl_hmac.c

#hexdigestString Also known as: inspect, to_s

Returns the authentication code an instance represents as a hex-encoded string.

Returns:

  • (String)


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ossl_hmac.c', line 206

static VALUE
ossl_hmac_hexdigest(VALUE self)
{
    EVP_MD_CTX *ctx;
    unsigned char buf[EVP_MAX_MD_SIZE];
    size_t buf_len = EVP_MAX_MD_SIZE;
    VALUE ret;

    GetHMAC(self, ctx);
    if (EVP_DigestSignFinal(ctx, buf, &buf_len) != 1)
        ossl_raise(eHMACError, "EVP_DigestSignFinal");
    ret = rb_str_new(NULL, buf_len * 2);
    ossl_bin2hex(buf, RSTRING_PTR(ret), buf_len);

    return ret;
}