2019-10-15 10:12:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var sha2 = module.exports;
|
|
|
|
|
|
|
|
var encoder = new TextEncoder();
|
2020-07-28 21:42:32 +00:00
|
|
|
sha2.sum = function (alg, str) {
|
2019-10-15 10:12:46 +00:00
|
|
|
var data = str;
|
|
|
|
if ('string' === typeof data) {
|
|
|
|
data = encoder.encode(str);
|
|
|
|
}
|
|
|
|
var sha = 'SHA-' + String(alg).replace(/^sha-?/i, '');
|
2020-08-20 07:02:18 +00:00
|
|
|
return window.crypto.subtle.digest(sha, data).then(function (buf) {
|
|
|
|
return new Uint8Array(buf);
|
|
|
|
});
|
2019-10-15 10:12:46 +00:00
|
|
|
};
|