Skip to main content
Module

x/jose/index.ts>CompactEncrypt

"JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto in Node.js, Browser, Cloudflare Workers, Electron, and Deno.
Extremely Popular
Go to Latest
class CompactEncrypt
import { CompactEncrypt } from "https://deno.land/x/jose@v4.8.3/index.ts";

The CompactEncrypt class is a utility for creating Compact JWE strings.

Examples

Usage

const jwe = await new jose.CompactEncrypt(
  new TextEncoder().encode(
    'It’s a dangerous business, Frodo, going out your door.'
  )
)
  .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
  .encrypt(publicKey)

console.log(jwe)

Constructors

new
CompactEncrypt(plaintext: Uint8Array)

Properties

private
_flattened: FlattenedEncrypt

Methods

encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<string>

Encrypts and resolves the value of the Compact JWE string.

deprecated
setContentEncryptionKey(cek: Uint8Array)

Sets a content encryption key to use, by default a random suitable one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.

deprecated
setInitializationVector(iv: Uint8Array)

Sets the JWE Initialization Vector to use for content encryption, by default a random suitable one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.

Sets the JWE Key Management parameters to be used when encrypting the Content Encryption Key. You do not need to invoke this method, it is only really intended for test and vector validation purposes.

Sets the JWE Protected Header on the CompactEncrypt object.