Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/hpke/core/mod.ts>CipherSuite

A Hybrid Public Key Encryption (HPKE) module built on top of Web Cryptography API.
Latest
class CipherSuite
extends CipherSuiteNative
import { CipherSuite } from "https://deno.land/x/hpke@1.2.7/core/mod.ts";

The Hybrid Public Key Encryption (HPKE) ciphersuite, which is implemented using only Web Cryptography API.

This class is the same as @hpke/core#CipherSuiteNative, which supports only the ciphersuites that can be implemented on the native Web Cryptography API. Therefore, the following cryptographic algorithms are not supported for now:

  • DHKEM(X25519, HKDF-SHA256)
  • DHKEM(X448, HKDF-SHA512)
  • ChaCha20Poly1305

In addtion, the HKDF functions contained in this CipherSuiteNative class can only derive keys of the same length as the hashSize.

If you want to use the unsupported cryptographic algorithms above or derive keys longer than the hashSize, please use hpke-js#CipherSuite.

This class provides following functions:

  • Creates encryption contexts both for senders and recipients.
    • createSenderContext
    • createRecipientContext
  • Provides single-shot encryption API.
    • seal
    • open

The calling of the constructor of this class is the starting point for HPKE operations for both senders and recipients.

Examples

Use only ciphersuites supported by Web Cryptography API.

import {
  Aes128Gcm,
  DhkemP256HkdfSha256,
  HkdfSha256,
  CipherSuite,
} from "http://deno.land/x/hpke/core/mod.ts";

const suite = new CipherSuite({
  kem: new DhkemP256HkdfSha256(),
  kdf: new HkdfSha256(),
  aead: new Aes128Gcm(),
});

Use a ciphersuite which is currently not supported by Web Cryptography API.

import { Aes128Gcm, HkdfSha256, CipherSuite } from "http://deno.land/x/hpke/core/mod.ts";
import { DhkemX25519HkdfSha256 } from "https://deno.land/x/hpke/x/dhkem-x25519/mod.ts";
const suite = new CipherSuite({
  kem: new DhkemX25519HkdfSha256(),
  kdf: new HkdfSha256(),
  aead: new Aes128Gcm(),
});