@hopeio/utils
Version:
javascript utils
37 lines (36 loc) • 888 B
JavaScript
import { webcrypto as p } from "crypto";
typeof crypto > "u" && (crypto = p);
const i = crypto, e = crypto.subtle;
async function u(t, n, r) {
const c = new TextEncoder().encode(t), o = new TextEncoder().encode(n), a = new TextEncoder().encode(r), y = await e.importKey(
"raw",
o,
{ name: "AES-CBC" },
!1,
["encrypt"]
), d = await e.encrypt(
{ name: "AES-CBC", iv: a },
y,
c
);
return btoa(String.fromCharCode.apply(null, new Uint8Array(d)));
}
async function w(t, n, r) {
const c = Uint8Array.from(atob(t), (f) => f.charCodeAt(0)), o = new TextEncoder().encode(n), a = new TextEncoder().encode(r), y = await e.importKey(
"raw",
o,
{ name: "AES-CBC" },
!1,
["decrypt"]
), d = await e.decrypt(
{ name: "AES-CBC", iv: a },
y,
c
);
return new TextDecoder().decode(d);
}
export {
i as c,
w as d,
u as e
};