Skip to content

Latest commit

 

History

History
119 lines (102 loc) · 2.82 KB

DES_EDE3_CBC.md

File metadata and controls

119 lines (102 loc) · 2.82 KB

DES-EDE3-CBC

WARNING: This is not compliant with the W3 WebCrypto specification.

Interfaces

DesCbcParams interface

interface DesEde3CbcParams {
    // The initialization vector. MUST be 8 bytes.
    iv: BufferSource;
}

Operations

Operation Parameters Result
generateKey DesKeyGenParams CryptoKey
importKey None CryptoKey
exportKey None JsonWebKey or BufferSource
encrypt DesEde3CbcParams ArrayBuffer
decrypt DesEde3CbcParams ArrayBuffer
wrapKey DesEde3CbcParams ArrayBuffer
unwrapKey DesEde3CbcParams CryptoKey

Generate key

const key = await crypto.subtle.generateKey(
  {
    name: "DES-EDE3-CBC",
    length: 192, // 192-bit only
  },
  false, // extractable
  ["encrypt", "decrypt", "wrapKey", "unwrapKey"], // key usages
);

Import key

const key = await crypto.subtle.importKey(
  "raw",   // raw or jwk
  rawData, // BufferSource
  "DES-EDE3-CBC",
  false,   // extractable
  ["encrypt", "decrypt"],
);

Export key

const raw = await crypto.subtle.exportKey(
  "raw", // raw or jwk
  key,
);

Encrypt

const iv = crypto.getRandomValues(new Uint8Array(8));

const encData = await crypto.subtle.encrypt(
  {
    name: "DES-EDE3-CBC",
    iv, // BufferSource
  },
  key,  // DES key
  data, // BufferSource
);

Decrypt

const data = await crypto.subtle.decrypt(
  {
    name: "DES-EDE3-CBC",
    iv, // BufferSource
  },
  key,  // DES key
  encData, // BufferSource
);

Wrap key

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-EDE3-CBC",
    iv, // BufferSource
  },
);

Unwrap key

const unwrappedKey = await crypto.subtle.unwrapKey(
  "pkcs8",    // raw, pkcs8, spki, or jwk
  wrappedKey, // BufferSource
  key,        // DES key
  {
    name: "DES-EDE3-CBC",
    iv, // BufferSource
  },
  {
    name: "RSA-PSS",
    hash: "SHA-256",
  }
  false,      // extractable
  ["sign", "verify"],
);