2019-10-15 10:12:46 +00:00
|
|
|
/* global Promise */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var sha2 = module.exports;
|
|
|
|
var crypto = require('crypto');
|
|
|
|
|
2020-07-28 21:42:32 +00:00
|
|
|
sha2.sum = function (alg, str) {
|
|
|
|
return Promise.resolve().then(function () {
|
2019-10-15 10:12:46 +00:00
|
|
|
var sha = 'sha' + String(alg).replace(/^sha-?/i, '');
|
|
|
|
// utf8 is the default for strings
|
|
|
|
var buf = Buffer.from(str);
|
2020-07-28 21:42:32 +00:00
|
|
|
return crypto.createHash(sha).update(buf).digest();
|
2019-10-15 10:12:46 +00:00
|
|
|
});
|
|
|
|
};
|