njs/crypto

Types

pub type CryptoKey
pub type CryptoKeyPair
pub type DecryptAlgorithm =
  EncryptAlgorithm
pub type EncryptAlgorithm {
  RsaOaep(name: String)
  AesCtr(name: String, counter: buffer.ArrayBuffer, length: Int)
  AesCbc(name: String, iv: buffer.ArrayBuffer)
  AesGcm(
    name: String,
    iv: buffer.ArrayBuffer,
    additional_data: buffer.ArrayBuffer,
    tag_length: Int,
  )
}

Constructors

pub type Hash
pub type Hmac
pub type KeyAlgorithm {
  RsaOaepKey(name: String, hash: String)
  HMACKey(name: String, hash: String, length: Int)
  AesKey(name: String)
  OKPKey(name: String)
}

Constructors

  • RsaOaepKey(name: String, hash: String)

    RSA-OAEP

  • HMACKey(name: String, hash: String, length: Int)

    HMAC

  • AesKey(name: String)

    AES-CTR AES-CBC AES-GCM AES-KW

  • OKPKey(name: String)

    Ed25519, X25519

pub type KeyData {
  KeyData(d: json.Json)
  KeyArrayData(d: buffer.ArrayBuffer)
}

Constructors

pub type SubtleCrypto

Values

pub fn compute_hash(
  algorithm a: String,
  data d: buffer.Buffer,
  encoding e: buffer.Encoding,
) -> promise.Promise(String)

Hash data through async WebCrypto and return the result as an encoded string. The raw node-style createHash/update/digest chain is also exposed above.

pub fn compute_hmac(
  algorithm a: String,
  key k: buffer.Buffer,
  data d: buffer.Buffer,
  encoding e: buffer.Encoding,
) -> promise.Promise(String)

Compute an HMAC through async WebCrypto and return it as an encoded string. The raw node-style createHmac/update/digest chain is also exposed above.

pub fn create_hash(algorithm a: String) -> Hash
pub fn create_hmac(algorithm a: String, key k: b) -> Hmac
pub fn crypto_key_algorithm(key k: CryptoKey) -> a
pub fn crypto_key_extractable(key k: CryptoKey) -> Bool
pub fn crypto_key_pair_private_key(
  key_pair kp: CryptoKeyPair,
) -> CryptoKey
pub fn crypto_key_pair_public_key(
  key_pair kp: CryptoKeyPair,
) -> CryptoKey
pub fn crypto_key_type(key k: CryptoKey) -> String
pub fn crypto_key_usages(key k: CryptoKey) -> array.Array(String)
pub fn decrypt(
  algorithm a: EncryptAlgorithm,
  key k: CryptoKey,
  ciphertext d: buffer.ArrayBuffer,
) -> promise.Promise(buffer.ArrayBuffer)
pub fn derive_bits(
  algorithm a: a,
  base_key k: CryptoKey,
  length l: Int,
) -> promise.Promise(buffer.ArrayBuffer)
pub fn derive_key(
  algorithm a: a,
  base_key k: CryptoKey,
  derived_key_algorithm dka: KeyAlgorithm,
  extractable e: Bool,
  key_usages ku: array.Array(String),
) -> promise.Promise(CryptoKey)
pub fn digest(
  algorithm a: String,
  data d: buffer.ArrayBuffer,
) -> promise.Promise(buffer.ArrayBuffer)
pub fn encrypt(
  algorithm a: EncryptAlgorithm,
  key k: CryptoKey,
  plaintext d: buffer.ArrayBuffer,
) -> promise.Promise(buffer.ArrayBuffer)
pub fn export_key(
  format f: String,
  key k: CryptoKey,
) -> promise.Promise(KeyData)
pub fn generate_key(
  algorithm a: KeyAlgorithm,
  extractable e: Bool,
  usages ku: array.Array(String),
) -> promise.Promise(CryptoKeyPair)
pub fn get_random_values(
  typedarray a: buffer.TypedArray,
) -> buffer.TypedArray
pub fn hash_constructor(
  hash h: Hash,
  algorithm a: String,
) -> Hash
pub fn hash_copy(hash h: Hash) -> Hash
pub fn hash_digest(
  hash h: Hash,
  encoding e: buffer.Encoding,
) -> String
pub fn hash_digest_buffer(hash h: Hash) -> buffer.Buffer
pub fn hash_update(hash h: Hash, data d: a) -> Hash
pub fn hmac_constructor(
  hmac h: Hmac,
  algorithm a: String,
  key k: b,
) -> Hmac
pub fn hmac_digest(
  hmac h: Hmac,
  encoding e: buffer.Encoding,
) -> String
pub fn hmac_digest_buffer(hmac h: Hmac) -> buffer.Buffer
pub fn hmac_update(hmac h: Hmac, data d: a) -> Hmac
pub fn import_key(
  format f: String,
  key k: buffer.ArrayBuffer,
  algorithm a: KeyAlgorithm,
  extractable e: Bool,
  usages ku: array.Array(String),
) -> promise.Promise(CryptoKey)
pub fn random_uuid() -> String

Generate a random UUID v4 string. Added in njs 0.9.7.

pub fn sign(
  algorithm a: a,
  key k: CryptoKey,
  data d: buffer.ArrayBuffer,
) -> promise.Promise(buffer.ArrayBuffer)
pub fn subtle() -> SubtleCrypto
pub fn unwrap_key(
  format f: String,
  wrapped_key wk: buffer.ArrayBuffer,
  unwrapping_key uk: CryptoKey,
  unwrap_algorithm ua: a,
  unwrapped_key_algorithm uka: KeyAlgorithm,
  extractable e: Bool,
  key_usages ku: array.Array(String),
) -> promise.Promise(CryptoKey)

Unwrap an encrypted key. Added in njs 0.9.7.

pub fn verify(
  algorithm a: a,
  key k: CryptoKey,
  signature s: buffer.ArrayBuffer,
  data d: buffer.ArrayBuffer,
) -> promise.Promise(Bool)
pub fn wrap_key(
  format f: String,
  key k: CryptoKey,
  wrapping_key wk: CryptoKey,
  algorithm a: a,
) -> promise.Promise(buffer.ArrayBuffer)

Wrap a CryptoKey using a wrapping key. Added in njs 0.9.7.

Search Document