Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var JsSHA = require('../src/sha');
- var crypto = require('crypto');
- /**
- * Convert hex string to binary string
- * @see {@link http://stackoverflow.com/a/7695514">http://stackoverflow.com/a/7695514}
- * @param {String} hex
- * @returns {String}
- */
- function hex2bin(hex){
- var bin = '',
- bytes = [],
- str,
- i;
- for(i = 0; i< hex.length-1; i += 2){
- bytes.push(parseInt(hex.substr(i, 2), 16));
- }
- str = String.fromCharCode.apply(String, bytes);
- if(str.length){
- bin = str;
- }
- return bin;
- }
- exports.jsShaFingerprint = function(test){
- var bin = hex2bin('E0113C18726D3AD74D6081C43D2539CA9A0A8745'),
- fingerBin = new JsSHA(bin, 'TEXT'),
- hashed = fingerBin.getHash('SHA-1', 'HEX');
- test.strictEqual(hashed.toUpperCase(), 'B153C0D8C766A64F677A3D1797E680D18EC571DD', 'generated hash equals expected hash');
- test.done();
- };
- exports.cryptoFingerprint = function(test){
- var sha1 = crypto.createHash('sha1');
- var bin = hex2bin('E0113C18726D3AD74D6081C43D2539CA9A0A8745'),
- fingerBin = sha1.update(bin),
- hashed = fingerBin.digest('hex');
- test.strictEqual(hashed.toUpperCase(), 'B153C0D8C766A64F677A3D1797E680D18EC571DD', 'generated hash equals expected hash');
- test.done();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement