Skip to content
FutureBlitz

    Install

    Import std.crypto.ciphers

    Aes256Gcm

    std.crypto.ciphers

    struct

    Public Struct Aes256Gcm

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

    Examples

    Local key = Aes256Gcm.NewKey()
    Local sealed = Aes256Gcm.Seal(key, "meet at noon")
    Expect(Aes256Gcm.Open(key, sealed) == "meet at noon".Bytes)
    // A changed byte, or another key, opens nothing.
    sealed[20] = sealed[20] ^ 1
    Expect(Aes256Gcm.Open(key, sealed) == Null)
    Expect(Aes256Gcm.Open(Aes256Gcm.NewKey(), Aes256Gcm.Seal(key, "hi")) == Null)

    std/crypto/ciphers.fb, line 36

    • 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.

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