Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Am trying the following in c# and its working,

/*creating base64 encoded signature in C#*/
C#
var secret = "#asecret#";
 var message = "Thu, 26 Oct 2017 06:41:08 GMT/myaccount/mymessage";
using (var hmac = new HMACSHA256())
  {
     hmac.Key = Convert.FromBase64String(secret);
     byte[] sigbyte = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
     sig = Convert.ToBase64String(sigbyte);
  }


Need help to convert the same to angularjs or java.

What I have tried:

I tried the following which is not working,

C#
String secret = "#asecret#";
String message = "Thu, 26 Oct 2017 06:41:08 GMT/myaccount/mymessage";

Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(),"HmacSHA256");
sha256_HMAC.init(secret_key);
String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
Posted
Updated 25-Oct-17 22:31pm
v2
Comments
Andy Lanng 26-Oct-17 4:00am    
Try to avoid including any avoid "secret" information in your posts. You never no what someone might piece together

1 solution

See java.security (Java Platform SE 8 )[^]. Don't know angular.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900