Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any method in javascript to genetare hash_hmac code. (Just like hash_hmac in php)

I have the php code to generate hash_hmac

$concate=array();
$validation_token = hash_hmac('md5', implode("|", $concate), 'hshalslkaslfhalkfhalsksaas');
echo $validation_token;

so now $validation_token is giving me the correct value. but I want these type of functionality in Javascript.

Can Any One Help Me. ?

Thanks in Advance.:)

like image 959
user3732525 Avatar asked Nov 21 '25 03:11

user3732525


1 Answers

there is no default functions but there are third party libarires that provide this functionality

  • Crypto-js is a good library that provides this feature ( see https://code.google.com/p/crypto-js/#HMAC) for how to generate HMAC codes using this library)

Here is an example

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-md5.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha512.js"></script>
<script>
    var hash = CryptoJS.HmacMD5("Message", "Secret Passphrase");
    var hash = CryptoJS.HmacSHA1("Message", "Secret Passphrase");
    var hash = CryptoJS.HmacSHA256("Message", "Secret Passphrase");
    var hash = CryptoJS.HmacSHA512("Message", "Secret Passphrase");
</script>

Note: The library is not very actively maintained,

like image 183
Manquer Avatar answered Nov 22 '25 15:11

Manquer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!