WARNING: This is not compliant with the W3 WebCrypto specification.
interface DesCbcParams {
// The initialization vector. MUST be 8 bytes.
iv: BufferSource;
}
Operation | Parameters | Result |
---|---|---|
generateKey | DesKeyGenParams | CryptoKey |
importKey | None | CryptoKey |
exportKey | None | JsonWebKey or BufferSource |
encrypt | DesCbcParams | ArrayBuffer |
decrypt | DesCbcParams | ArrayBuffer |
wrapKey | DesCbcParams | ArrayBuffer |
unwrapKey | DesCbcParams | CryptoKey |
const key = await crypto.subtle.generateKey(
{
name: "DES-CBC",
length: 64, // 64-bit only
},
false, // extractable
["encrypt", "decrypt", "wrapKey", "unwrapKey"], // key usages
);
const key = await crypto.subtle.importKey(
"raw", // raw or jwk
rawData, // BufferSource
"DES-CBC",
false, // extractable
["encrypt", "decrypt"],
);
const raw = await crypto.subtle.exportKey(
"raw", // raw or jwk
key,
);
const iv = crypto.getRandomValues(new Uint8Array(8));
const encData = await crypto.subtle.encrypt(
{
name: "DES-CBC",
iv, // BufferSource
},
key, // DES key
data, // BufferSource
);
const data = await crypto.subtle.decrypt(
{
name: "DES-CBC",
iv, // BufferSource
},
key, // DES key
encData, // BufferSource
);
const iv = crypto.getRandomValues(new Uint8Array(8));
const wrappedKey = await crypto.subtle.wrapKey(
"pkcs8", // raw, pkcs8, spki, or jwk
anyKey, // Crypto key
key, // DES key
{
name: "DES-CBC",
iv, // BufferSource
},
);
const unwrappedKey = await crypto.subtle.unwrapKey(
"pkcs8", // raw, pkcs8, spki, or jwk
wrappedKey, // BufferSource
key, // DES key
{
name: "DES-CBC",
iv, // BufferSource
},
{
name: "RSA-PSS",
hash: "SHA-256",
}
false, // extractable
["sign", "verify"],
);