class

AesGcm::Cipher

Inherits Reference < Object

Main cipher class for AES-256-GCM operations

Constructors

new(iv_size : Int32 = 12, tag_size : Int32 = 16, key_size : Int32 = 32)
Source

Instance methods

decrypt(key : String | Bytes, ciphertext : Bytes, iv : Bytes, auth_tag : Bytes) : Bytes

Decrypt ciphertext using AES-256-GCM

Parameters:

  • key: 32-byte encryption key (String or Bytes)
  • ciphertext: Encrypted data (Bytes)
  • iv: Initialization vector used during encryption
  • auth_tag: Authentication tag from encryption

Returns: Decrypted data as Bytes Raises: OpenSSL::Cipher::Error if authentication fails or data is corrupted

Source
decrypt(encrypted : EncryptedData, key : String | Bytes) : Bytes

Decrypt from EncryptedData struct

Source
decrypt_base64(encoded : String, key : String | Bytes) : Bytes

Helper method to decrypt from base64-encoded string

Source
encrypt(key : String | Bytes, plaintext : String | Bytes, iv : Bytes | Nil = nil) : EncryptedData

Encrypt plaintext using AES-256-GCM

Parameters:

  • key: 32-byte encryption key (String or Bytes)
  • plaintext: Data to encrypt (String or Bytes)
  • iv: Optional initialization vector (defaults to random)

Returns: EncryptedData containing ciphertext, iv, and auth_tag

Source
encrypt_base64(key : String | Bytes, plaintext : String | Bytes) : String

Helper method to encrypt and return base64-encoded string

Source
iv_size
Source
iv_size=(iv_size : Int32)
Source
key_size
Source
key_size=(key_size : Int32)
Source
tag_size
Source
tag_size=(tag_size : Int32)
Source