最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论

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

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

Share edited Apr 28, 2016 at 14:51 Manquer 7,6478 gold badges45 silver badges71 bronze badges asked Jun 12, 2014 at 4:33 user3732525user3732525 271 silver badge3 bronze badges 1
  • 1 possible duplicate of Need HMAC SHA1 encryption library for javascript – cegfault Commented Jun 12, 2014 at 4:38
Add a ment  | 

1 Answer 1

Reset to default 7

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./p/crypto-js/#HMAC) for how to generate HMAC codes using this library)

Here is an example

<script src="http://crypto-js.googlecode./svn/tags/3.1.2/build/rollups/hmac-md5.js"></script>
<script src="http://crypto-js.googlecode./svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode./svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode./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,

发布评论

评论列表(0)

  1. 暂无评论