acme.js/lib/browser/sha2.js

14 lines
299 B
JavaScript
Raw Permalink Normal View History

2019-10-04 23:35:59 +00:00
'use strict';
var sha2 = module.exports;
var encoder = new TextEncoder();
2020-07-28 21:53:50 +00:00
sha2.sum = function (alg, str) {
2019-10-04 23:35:59 +00:00
var data = str;
if ('string' === typeof data) {
data = encoder.encode(str);
}
var sha = 'SHA-' + String(alg).replace(/^sha-?/i, '');
return window.crypto.subtle.digest(sha, data);
};