Skip to content
FutureBlitz

    Install

    Import std.crypto.ciphers

    std.crypto.ciphers

    Aes256Gcm and ChaCha20Poly1305, over mbedTLS: authenticated encryption, which keeps a message secret and tells whether it was changed. Seal takes a new random nonce for each message and puts it first in what it gives, so a nonce is never given, and never reused but by a chance of about 1 in 2^33 after 2^32 messages under one key, which is as many as a key should seal. Open gives Null for anything Seal didn't make with that key and associated data.

    std/crypto/ciphers.fb

    Types

    Aes256Gcm struct

    Public Struct Aes256Gcm

    AES-256 in GCM (NIST SP 800-38D), fast where the CPU has AES instructions.

    std/crypto/ciphers.fb, line 22

    • Public Static Method NewKey(): UInt8[] static method #

      A new random key, 32 bytes.

    • @PanicsAtCaller Public Static Method Seal(key: UInt8[], message: UInt8[], associated: UInt8[] = []): UInt8[] static method #

      message, encrypted with key, 32 bytes: the nonce, 12 bytes, the ciphertext, as long as message, and the tag, 16 bytes, which authenticates them and associated, data that isn't encrypted but has to be the same to open it. Panics unless key is 32 bytes.

    • @PanicsAtCaller Public Static Method Seal(key: UInt8[], text: String, associated: UInt8[] = []): UInt8[] static method #

      text's UTF-8 bytes, encrypted with key, as the Seal that takes bytes does.

    • @PanicsAtCaller Public Static Method Open(key: UInt8[], sealed: UInt8[], associated: UInt8[] = []): UInt8[]? static method #

      The message Seal sealed into sealed, or Null when sealed isn't what Seal gave for key and associated, or was changed. Panics unless key is 32 bytes.

    ChaCha20Poly1305 struct

    Public Struct ChaCha20Poly1305

    ChaCha20 and Poly1305 (RFC 8439), fast on any CPU, with or without AES instructions.

    std/crypto/ciphers.fb, line 54

    • Public Static Method NewKey(): UInt8[] static method #

      A new random key, 32 bytes.

    • @PanicsAtCaller Public Static Method Seal(key: UInt8[], message: UInt8[], associated: UInt8[] = []): UInt8[] static method #

      As Aes256Gcm's Seal.

    • @PanicsAtCaller Public Static Method Seal(key: UInt8[], text: String, associated: UInt8[] = []): UInt8[] static method #

      text's UTF-8 bytes, encrypted with key, as the Seal that takes bytes does.

    • @PanicsAtCaller Public Static Method Open(key: UInt8[], sealed: UInt8[], associated: UInt8[] = []): UInt8[]? static method #

      As Aes256Gcm's Open.

    Report an issue with this page or with FutureBlitz on GitHub.