Skip to main content
Go to Latest
function cryptoEncrypt
import { cryptoEncrypt } from "https://deno.land/x/simple_utility@v0.3.1/mod.universal.ts";

Encrypt binary. Algorithm use is "AES-GCM" with 256 bits key, 128 bits tag and 96 bits IV. IV is prepended to cipher.

Examples

Example 1

const bin = await Deno.readFile("./file");
const key1 = await cryptoGenerateKey(true);
const key2 = await cryptoGenerateKey(true);
const converted = await cryptoEncrypt({
    publicKey: key1.publicKey,
    privateKey: key2.privateKey
}, bin);
const restored = await cryptoDecrypt({
    publicKey: key2.publicKey,
    privateKey: key1.privateKey
}, converted);

Parameters

data: Uint8Array