24 lines
683 B
TypeScript
24 lines
683 B
TypeScript
import {Aes} from "https://deno.land/x/crypto@v0.10.0/aes.ts";
|
|
import {Cbc, Padding} from "https://deno.land/x/crypto@v0.10.0/block-modes.ts";
|
|
|
|
const te = new TextEncoder();
|
|
|
|
const key = te.encode("EmmaHasHugeTitts");
|
|
const data = te.encode("DataToBeEncrypted");
|
|
const iv = new Uint8Array(16);
|
|
|
|
const cipher = new Cbc(Aes, key, iv, Padding.PKCS7)
|
|
const decipher = new Cbc(Aes, key, iv, Padding.PKCS7)
|
|
|
|
const encrypted = cipher.encrypt(data);
|
|
const decrypted = decipher.decrypt(encrypted);
|
|
|
|
console.decode = function (encoded: Uint8Array) {
|
|
const td = new TextDecoder();
|
|
this.log(td.decode(encoded));
|
|
}
|
|
|
|
console.decode(data);
|
|
console.decode(encrypted);
|
|
console.decode(decrypted);
|