java - Signature with HMAC SHA-256 and Base64Encoder -



java - Signature with HMAC SHA-256 and Base64Encoder -

i tried lot creating signature access 1 web service.

they required generate signature each request.

for generating signature, have 1 message "abc" , 1 secrete key "xyz". according them signature should processed next ruby code

require 'base64' require 'openssl' secret = "xyz" request = "abc" digest = openssl::digest::digest.new('sha256') signature = base64.encode64(openssl::hmac.digest(digest, secret, request)).chomp

signature should 9zjsfvb3k5npnlf5he+gfyyaxnwcij6j8ycrpxw5gg0= not getting using java code below:

secretkey secretkey = null; byte[] keybytes = keystring.getbytes("utf-8"); mac mac = mac.getinstance("hmachsa256"); secretkey = new secretkeyspec(keybytes,mac.getalgorithm()); mac.init(secretkey); byte[] text = basestring.getbytes("utf-8"); //mac.update(digest.digest()); byte[] encodedtext = mac.dofinal(text); homecoming new string(base64.encodebase64(encodedtext)).trim();

please help me on this.

i ran java code , got oqljgtdh255vg5ix4fjvzhvfoq7tnygjrcbq/enf8je=

i went this online site , got oqljgtdh255vg5ix4fjvzhvfoq7tnygjrcbq/enf8je=

i ran top script ruby script, , got oqljgtdh255vg5ix4fjvzhvfoq7tnygjrcbq/enf8je=

since 3 match, suggest code above consistent value study not correct. above java code pretty much textbook hmacsha256 java cannot comment on ruby part because java guy.

java ruby base64 digital-signature hmac

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -