user3732525
user3732525

Reputation: 27

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.:)

Upvotes: 3

Views: 4091

Answers (1)

Manquer
Manquer

Reputation: 7647

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

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,

Upvotes: 7

Related Questions