Class: Omnizip::Crypto::Aes256::Cipher
- Inherits:
-
Object
- Object
- Omnizip::Crypto::Aes256::Cipher
- Includes:
- Constants
- Defined in:
- lib/omnizip/crypto/aes256/cipher.rb
Overview
AES-256-CBC cipher operations
Wraps OpenSSL's AES-256-CBC implementation with proper padding and error handling for 7-Zip compatibility.
Constant Summary
Constants included from Constants
Omnizip::Crypto::Aes256::Constants::BLOCK_SIZE, Omnizip::Crypto::Aes256::Constants::DEFAULT_CYCLES_POWER, Omnizip::Crypto::Aes256::Constants::IV_SIZE, Omnizip::Crypto::Aes256::Constants::KEY_SIZE, Omnizip::Crypto::Aes256::Constants::MAX_CYCLES_POWER, Omnizip::Crypto::Aes256::Constants::MIN_CYCLES_POWER, Omnizip::Crypto::Aes256::Constants::SALT_SIZE, Omnizip::Crypto::Aes256::Constants::SALT_SIZE_MAX
Instance Attribute Summary collapse
-
#iv ⇒ Object
readonly
Returns the value of attribute iv.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#decrypt(ciphertext) ⇒ String
Decrypt data using AES-256-CBC.
-
#encrypt(plaintext) ⇒ String
Encrypt data using AES-256-CBC.
-
#initialize(key, iv) ⇒ Cipher
constructor
Initialize cipher with key and IV.
Constructor Details
#initialize(key, iv) ⇒ Cipher
Initialize cipher with key and IV
23 24 25 26 27 |
# File 'lib/omnizip/crypto/aes256/cipher.rb', line 23 def initialize(key, iv) validate_key_iv(key, iv) @key = key @iv = iv end |
Instance Attribute Details
#iv ⇒ Object (readonly)
Returns the value of attribute iv.
17 18 19 |
# File 'lib/omnizip/crypto/aes256/cipher.rb', line 17 def iv @iv end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
17 18 19 |
# File 'lib/omnizip/crypto/aes256/cipher.rb', line 17 def key @key end |
Instance Method Details
#decrypt(ciphertext) ⇒ String
Decrypt data using AES-256-CBC
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/omnizip/crypto/aes256/cipher.rb', line 51 def decrypt(ciphertext) cipher = create_cipher(:decrypt) # Handle empty or very small ciphertext if ciphertext.empty? return "" end result = cipher.update(ciphertext) result << cipher.final result end |
#encrypt(plaintext) ⇒ String
Encrypt data using AES-256-CBC
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omnizip/crypto/aes256/cipher.rb', line 33 def encrypt(plaintext) cipher = create_cipher(:encrypt) # Handle empty data - just call final() for padding if plaintext.empty? return cipher.final end result = cipher.update(plaintext) result << cipher.final result end |