@openpass/openpass-js-sdk
Version:
OpenPass SSO JavaScript SDK
17 lines • 647 B
JavaScript
const cryptoApi = () => window.crypto || window.msCrypto;
const cryptoSubtleApi = () => {
const crypto = cryptoApi();
return crypto.subtle || crypto.webkitSubtle;
};
export const generateRandomString = (length = 43) => {
const array = new Uint32Array(length);
cryptoApi().getRandomValues(array);
return Array.from(array, (item) => `0${item.toString(16)}`.slice(-2)).join("");
};
export const hashSha256 = async (value) => {
const encoder = new TextEncoder();
const data = encoder.encode(value);
const buffer = await cryptoSubtleApi().digest("SHA-256", data);
return buffer;
};
//# sourceMappingURL=crypto.js.map