hmac_sha512 to jsSHA

A quick conversion of hmac_sha512 of php to a javascript library based jsSHA.

e.g. if we had the php code:

<?php
$sign = hash_hmac('sha512', $post_data, $secret);
echo $sign;

This can be converted to the jsSHA based javascript code like this:

var shaObj = new jsSHA("SHA-512", "TEXT");
shaObj.setHMACKey(secret, "TEXT");
shaObj.update(post_data);
var hmac = shaObj.getHMAC("HEX");

I hope this helps.

The post_data in javascript example is the data that we sent to this page maybe. This is the password or text that we need to use in our code and apply encryption to.

2 comments on “hmac_sha512 to jsSHA

Leave a Reply

Your email address will not be published.