3

what is the equivalent HMAC SHA-512 key for the following one? 01c17afc4be444d9f27ff3b11cd206f79cbcd0fa7e262d90587338f7d5a70f92

What is the code use to get for this in ruby? I found no online converters to check this with HMAC.

Sam
  • 5,040
  • 12
  • 43
  • 95
  • What do you mean by "equivalent"? The string you presented looks like a HEX encoding of 32 bytes which can be used as a key for HMAC SHA-512. – Oleg Estekhin Jul 03 '14 at 05:59

1 Answers1

4

You can use following code to create signature using HMAC and sha512 in ruby,

digest = OpenSSL::Digest.new('sha512')
signature = OpenSSL::HMAC.digest(digest, private_key, data)

The "data" is the actual data that you want to sign. if you just want to create instance then you can use instance = OpenSSL::HMAC.new(private_key, digest) and then update method.

For more information on HMAC using ruby with sample code -

http://ruby-doc.org/stdlib-2.1.0/libdoc/openssl/rdoc/OpenSSL/HMAC.html

Vaibhav Vidhate
  • 186
  • 1
  • 5
  • What is data? I want to pass only private_key – Sam Jun 25 '14 at 10:50
  • The "data" is data that you you want to sign. if you just want to create instance then you can use `instance = OpenSSL::HMAC.new(private_key, digest)` – Vaibhav Vidhate Jun 25 '14 at 11:29
  • Kindly read my question. My requirement is just find the equivalent HMAC sha512 value for the above key. i.e 01c17afc4be444d9f27ff3b11cd206f79cbcd0fa7e262d90587338f7d5a70f92 – Sam Jun 25 '14 at 11:34
  • `hexdigest` probably should be used instead of `digest` – brauliobo Jul 02 '16 at 19:18