Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hmac256 issue in c# #26

Open
ClayBorkholm opened this issue Jun 4, 2019 · 1 comment
Open

hmac256 issue in c# #26

ClayBorkholm opened this issue Jun 4, 2019 · 1 comment

Comments

@ClayBorkholm
Copy link

Thanks for compiling the list - it's very helpful. The c# code works, but it won't work more broadly in that you've used an encoding that is different than most of the other examples. In particular, you're using System.Text.ASCIIEncoding() and you should be using System.Text.UTF8Encoding(). The results are identical with the simple test, but will fail with extended Unicode characters.

string CreateToken( string message, string secret )
{
   var encoding = new System.Text.UTF8Encoding( );
   var keyBytes = encoding.GetBytes( secret );
   var messageBytes = encoding.GetBytes( Message );
   using ( var hmacsha256 = new HMACSHA256( keyBytes ) )
   {
     var hashmessage = hmacsha256.ComputeHash( messageBytes );
     return Convert.ToBase64String( hashmessage );
   }
}
@jokecamp
Copy link
Owner

jokecamp commented Jun 5, 2019

This is a good point. Thank you. I'll get this updated soon. Feel free to make a pull request if you would like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants