Generate SHA256 in c++ -


i need generate sha256 of data. found this example one. question can generate sha256 using own key.

edit:

first of all, sorry wrong question. don't mean change key used generate sha256. need that, convert following java code c++

public static string calculatehmac(string data, string key) throws exception { string result; try {     // hmac_sha2 key raw key bytes     secretkeyspec signingkey = new secretkeyspec(key.getbytes(), hmac_sha2_algorithm);      // hmac_sha1 mac instance , initialize signing key     mac sha256_hmac = mac.getinstance(hmac_sha2_algorithm);     sha256_hmac.init(signingkey);      // compute hmac on input data bytes     byte[] rawhmac = sha256_hmac.dofinal(data.getbytes());      // base64-encode hmac      stringbuilder sb = new stringbuilder();     char[] chararray = base64.encode(rawhmac);         ( char : chararray){             sb.append(a);             }         result = sb.tostring();     }     catch (exception e) {         throw new signatureexception("failed generate hmac : " + e.getmessage());     }     return result; } 

i recommend free crypto++ library. here's sample hmac.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -