javascript 实现sm3哈希算法
各位看官直接上code,随copy随食用。
分别建三个js文件:
- sm_utils.js
var utils = exports
utils.strToBytes = strToBytes
function strToBytes(s) {
var ch, st, re = [];
for (var i = 0; i < s.length; i++ ) {
ch = s.charCodeAt(i); // get char
st = []; // set up "stack"
do {
st.push( ch & 0xFF ); // push byte to stack
ch = ch >> 8; // shift value down by 1 byte
}
while ( ch );
re = re.concat( st.reverse() );
}
return re;
}
- sm_sm3.js
/**
* SM3 hash algorithm
*/
var utils = require('./sm_utils');
/**
* SM3 Hasher
*/
function SM3() {
if (!(this instanceof SM3)) {
return new SM3();
}
this.reg = new Array(8);
thi
版权声明:本文为Shen_yuanjia原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。