Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

新旧版本为什么 md5值不一样

$
0
0

测试代码





String.prototype.hexEncode = function(){
    var hex, i;

    var result = "";
    for (i=0; i<this.length; i++) {
        hex = this.charCodeAt(i).toString(16);
        result += (" "+hex).slice(-4);
    }

    return result
}



var crypto=require('crypto');
var fs=require('fs');

var arr=[0x0,0x0,0x4d,0x67,0x0,0x0,0xa,0x28,0x5a,0x73,0xde,0x69,0x57,0xdc,0x4a,0x85];
const srcdata = new Buffer(arr, 'binary');
var md5= crypto.createHash('md5').update(srcdata).digest('hex');
console.log(md5)


fs.writeFileSync('md5',srcdata, 'binary');

var data=fs.readFileSync('md5', 'binary');
console.log(data.hexEncode());

 md5= crypto.createHash('md5').update(data).digest('hex');
 console.log(md5)

直接用字节初始化,md5值是对的,但是经过写入文件,再读出来 node 4.2 是一致的, 最新7.0算出的md5值不一样

d74fb898905fdc30d20f75456feb9c1f 0 0 4d 67 0 0 a 28 5a 73 de 69 57 dc 4a 85 a0becbcc2e7e48bb0585dc7d9ff16b76


Viewing all articles
Browse latest Browse all 14821

Trending Articles