Spec-Zone.ru › Deno 2

Crypto

Cryptographic functionality for secure communication, data protection, and key management. Generate secure random numbers, encrypt and decrypt data, and manage cryptographic keys.

Eg crypto


interface AesCbcParams

extends Algorithm

Properties

iv: BufferSource

interface AesCtrParams

extends Algorithm

Properties

counter: BufferSource
length: number

interface AesDerivedKeyParams

extends Algorithm

Properties

length: number

interface AesGcmParams

extends Algorithm

Properties

iv: BufferSource
additionalData: BufferSource
optional
tagLength: number
optional

interface AesKeyAlgorithm

extends KeyAlgorithm

Properties

length: number

interface AesKeyGenParams

extends Algorithm

Properties

length: number

interface Algorithm

Properties

name: string

interface Crypto

This Web Crypto API interface provides basic cryptographic functionality. It is accessed via the global crypto property, which gives access to cryptographically strong random number generation and to the low-level primitives exposed by SubtleCrypto through Crypto.subtle.

Properties

subtle: SubtleCrypto
readonly

Methods

getRandomValues<T extends ArrayBufferView>(array: T): T

Mutates the provided typed array with cryptographically secure random values.

randomUUID(): `${string}-${string}-${string}-${string}-${string}`

Generates a random RFC 4122 version 4 UUID using a cryptographically secure random number generator.

variable Crypto

The constructor object for Crypto.

The Crypto instance is accessed via the global crypto property rather than constructed directly, so calling the constructor throws.

Properties

prototype: Crypto
readonly

interface CryptoKey

The CryptoKey dictionary of the Web Crypto API represents a cryptographic key.

Properties

algorithm: KeyAlgorithm
readonly
extractable: boolean
readonly
type: KeyType
readonly
usages: KeyUsage[]
readonly

variable CryptoKey

The constructor object for CryptoKey.

CryptoKey instances cannot be created directly; they are produced by SubtleCrypto methods such as generateKey, importKey, and deriveKey, so calling the constructor throws.

Properties

prototype: CryptoKey
readonly

interface CryptoKeyPair

The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for an asymmetric cryptography algorithm, also known as a public-key algorithm.

Properties

privateKey: CryptoKey
publicKey: CryptoKey

variable CryptoKeyPair

The constructor object for CryptoKeyPair.

CryptoKeyPair objects are returned by SubtleCrypto.generateKey for asymmetric algorithms and cannot be constructed directly, so calling the constructor throws.

Properties

prototype: CryptoKeyPair
readonly

interface EcdhKeyDeriveParams

extends Algorithm

Properties

public: CryptoKey

interface EcdsaParams

extends Algorithm

Properties

hash: HashAlgorithmIdentifier

interface EcKeyAlgorithm

extends KeyAlgorithm

Properties

namedCurve: NamedCurve

interface EcKeyGenParams

extends Algorithm

Properties

namedCurve: NamedCurve

interface EcKeyImportParams

extends Algorithm

Properties

namedCurve: NamedCurve

interface HkdfParams

extends Algorithm

Properties

hash: HashAlgorithmIdentifier
info: BufferSource
salt: BufferSource

interface HmacImportParams

extends Algorithm

Properties

hash: HashAlgorithmIdentifier
length: number
optional

interface HmacKeyAlgorithm

extends KeyAlgorithm

Properties

hash: KeyAlgorithm
length: number

interface HmacKeyGenParams

extends Algorithm

Properties

hash: HashAlgorithmIdentifier
length: number
optional

interface JsonWebKey

Properties

alg: string
optional
crv: string
optional
d: string
optional
dp: string
optional
dq: string
optional
e: string
optional
ext: boolean
optional
k: string
optional
key_ops: string[]
optional
kty: string
optional
n: string
optional
oth: RsaOtherPrimesInfo[]
optional
p: string
optional
q: string
optional
qi: string
optional
use: string
optional
x: string
optional
y: string
optional

interface KeyAlgorithm

Properties

name: string

interface Pbkdf2Params

extends Algorithm

Properties

hash: HashAlgorithmIdentifier
iterations: number
salt: BufferSource

interface RsaHashedImportParams

extends Algorithm

Properties

hash: HashAlgorithmIdentifier

interface RsaHashedKeyAlgorithm

extends RsaKeyAlgorithm

Properties

hash: KeyAlgorithm

interface RsaHashedKeyGenParams

extends RsaKeyGenParams

Properties

hash: HashAlgorithmIdentifier

interface RsaKeyAlgorithm

extends KeyAlgorithm

Properties

modulusLength: number
publicExponent: BigInteger

interface RsaKeyGenParams

extends Algorithm

Properties

modulusLength: number
publicExponent: BigInteger

interface RsaOaepParams

extends Algorithm

Properties

label: BufferSource
optional

interface RsaOtherPrimesInfo

Properties

d: string
optional
r: string
optional
t: string
optional

interface RsaPssParams

extends Algorithm

Properties

saltLength: number

interface SubtleCrypto

This Web Crypto API interface provides a number of low-level cryptographic functions. It is accessed via the Crypto.subtle properties available in a window context (via globalThis.crypto).

Methods

generateKey(
algorithm: RsaHashedKeyGenParams | EcKeyGenParams,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKeyPair>

Generates an asymmetric cryptographic key pair for encryption, signing, or key exchange.

This overload is used for generating key pairs with RSA or elliptic curve algorithms.

generateKey(
algorithm: AesKeyGenParams | HmacKeyGenParams,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

Generates a symmetric cryptographic key for encryption, authentication, or hashing.

This overload is used for algorithms such as AES and HMAC.

generateKey(
algorithm: AlgorithmIdentifier,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKeyPair | CryptoKey>

Generates a cryptographic key or key pair for a given algorithm.

This generic overload handles any key generation request, returning either a symmetric key or an asymmetric key pair based on the provided algorithm.

importKey(
format: "jwk",
keyData: JsonWebKey,
algorithm:
AlgorithmIdentifier
| HmacImportParams
| RsaHashedImportParams
| EcKeyImportParams
,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

Imports a cryptographic key in JSON Web Key (JWK) format.

This method is used to import an asymmetric key (e.g., RSA or ECDSA) from a JWK object. JWK allows structured representation of keys, making them portable across different systems.

importKey(
format: Exclude<KeyFormat, "jwk">,
keyData: BufferSource,
algorithm:
AlgorithmIdentifier
| HmacImportParams
| RsaHashedImportParams
| EcKeyImportParams
,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

Imports a cryptographic key in raw, PKCS8, or SPKI format.

This method is used to import symmetric keys (e.g., AES), private keys (PKCS8), or public keys (SPKI).

exportKey(
format: "jwk",
key: CryptoKey,
): Promise<JsonWebKey>

Exports a cryptographic key in JSON Web Key (JWK) format.

This method allows exporting an asymmetric key (e.g., RSA, ECDSA) into a JSON-based representation, making it easy to store and transfer across systems.

exportKey(
format: Exclude<KeyFormat, "jwk">,
key: CryptoKey,
): Promise<ArrayBuffer>

Exports a cryptographic key in raw, PKCS8, or SPKI format.

This method is used to export symmetric keys (AES), private keys (PKCS8), or public keys (SPKI) in binary form.

sign(
algorithm:
AlgorithmIdentifier
| RsaPssParams
| EcdsaParams
,
key: CryptoKey,
data: BufferSource,
): Promise<ArrayBuffer>

Generates a digital signature using a private cryptographic key.

This method is used to sign data with an asymmetric key (e.g., RSA-PSS, ECDSA).

verify(
algorithm:
AlgorithmIdentifier
| RsaPssParams
| EcdsaParams
,
key: CryptoKey,
signature: BufferSource,
data: BufferSource,
): Promise<boolean>

Verifies a digital signature using a public cryptographic key.

This method checks whether a signature is valid for the given data.

digest(
algorithm: AlgorithmIdentifier,
data: BufferSource,
): Promise<ArrayBuffer>

Computes a cryptographic hash (digest) of the given data.

This method is commonly used for verifying data integrity.

encrypt(
algorithm:
AlgorithmIdentifier
| RsaOaepParams
| AesCbcParams
| AesGcmParams
| AesCtrParams
,
key: CryptoKey,
data: BufferSource,
): Promise<ArrayBuffer>

Encrypts data using a cryptographic key.

This method is used with both symmetric (AES) and asymmetric (RSA) encryption.

decrypt(
algorithm:
AlgorithmIdentifier
| RsaOaepParams
| AesCbcParams
| AesGcmParams
| AesCtrParams
,
key: CryptoKey,
data: BufferSource,
): Promise<ArrayBuffer>

Decrypts previously encrypted data using a cryptographic key.

deriveBits(
algorithm:
AlgorithmIdentifier
| HkdfParams
| Pbkdf2Params
| EcdhKeyDeriveParams
,
baseKey: CryptoKey,
length: number,
): Promise<ArrayBuffer>

This method is used to derive a key from a base key using a cryptographic algorithm.

deriveKey(
algorithm:
AlgorithmIdentifier
| HkdfParams
| Pbkdf2Params
| EcdhKeyDeriveParams
,
baseKey: CryptoKey,
derivedKeyType:
AlgorithmIdentifier
| AesDerivedKeyParams
| HmacImportParams
| HkdfParams
| Pbkdf2Params
,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

This method is used to derive a secret key from a base or master key using a cryptographic algorithm. It returns a Promise which fulfils with an object of the new key.

wrapKey(
format: KeyFormat,
key: CryptoKey,
wrappingKey: CryptoKey,
wrapAlgorithm:
AlgorithmIdentifier
| RsaOaepParams
| AesCbcParams
| AesCtrParams
,
): Promise<ArrayBuffer>

Wraps (encrypts) a cryptographic key for secure storage or transmission

unwrapKey(
format: KeyFormat,
wrappedKey: BufferSource,
unwrappingKey: CryptoKey,
unwrapAlgorithm:
AlgorithmIdentifier
| RsaOaepParams
| AesCbcParams
| AesCtrParams
,
unwrappedKeyAlgorithm:
AlgorithmIdentifier
| HmacImportParams
| RsaHashedImportParams
| EcKeyImportParams
,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>

Unwraps (decrypts) a previously wrapped key.

variable SubtleCrypto

The constructor object for SubtleCrypto.

The SubtleCrypto instance is accessed via Crypto.subtle (crypto.subtle) rather than constructed directly, so calling the constructor throws.

Properties

prototype: SubtleCrypto
readonly

Methods

supports(
operation:
"encrypt"
| "decrypt"
| "sign"
| "verify"
| "digest"
| "generateKey"
| "deriveKey"
| "deriveBits"
| "importKey"
| "exportKey"
| "wrapKey"
| "unwrapKey"
| "encapsulateKey"
| "encapsulateBits"
| "decapsulateKey"
| "decapsulateBits"
| "getPublicKey"
,
algorithm: string | object,
lengthOrHash?:
number
| string
| object
| null
,
): boolean

Synchronous feature detection for Web Crypto algorithm/operation combinations, per the WICG "Modern Algorithms in the Web Crypto API" proposal. Returns true when this runtime implements the requested combination, false otherwise.

The third argument is interpreted as the derived-bit length when it is a number (relevant for "deriveBits"), and as a related algorithm — e.g. the derived-key algorithm for "deriveKey", the wrapped/unwrapped key algorithm for "wrapKey" / "unwrapKey", or the shared-key algorithm for "encapsulateKey" / "decapsulateKey" — otherwise.


type alias AlgorithmIdentifier

Definition

string | Algorithm

type alias BigInteger

Definition

Uint8Array<ArrayBuffer>

type alias HashAlgorithmIdentifier

Definition

AlgorithmIdentifier

type alias KeyFormat

Definition

"jwk"
| "pkcs8"
| "raw"
| "raw-secret"
| "raw-public"
| "raw-private"
| "raw-seed"
| "spki"

type alias KeyType

Definition

"private"
| "public"
| "secret"

type alias KeyUsage

Definition

"decrypt"
| "deriveBits"
| "deriveKey"
| "encrypt"
| "sign"
| "unwrapKey"
| "verify"
| "wrapKey"

type alias NamedCurve

Definition

string

variable crypto

The global instance of Crypto that provides access to the Web Crypto API, including cryptographically secure random number generation via Crypto.getRandomValues, random UUID generation via Crypto.randomUUID, and the low-level primitives exposed by SubtleCrypto through Crypto.subtle.

Type

Crypto

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/web/crypto

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API