Class: Omnizip::Formats::Rar::Rar5::Encryption::Aes256Cbc
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Rar5::Encryption::Aes256Cbc
- Defined in:
- lib/omnizip/formats/rar/rar5/encryption/aes256_cbc.rb
Overview
AES-256-CBC cipher for RAR5 encryption
Wrapper around the existing Crypto::Aes256::Cipher that provides RAR5-specific encryption/decryption with proper key and IV handling.
RAR5 uses:
- AES-256 in CBC mode
- PKCS#7 padding
- Per-file IV generation
- PBKDF2-HMAC-SHA256 key derivation
Constant Summary collapse
- IV_SIZE =
IV size (16 bytes = AES block size)
16- KEY_SIZE =
Key size (32 bytes for AES-256)
32
Instance Attribute Summary collapse
-
#iv ⇒ String
readonly
Initialization vector (16 bytes).
-
#key ⇒ String
readonly
AES-256 key (32 bytes).
Class Method Summary collapse
-
.generate_iv ⇒ String
Generate random IV.
Instance Method Summary collapse
-
#decrypt(ciphertext) ⇒ String
Decrypt data.
-
#encrypt(plaintext) ⇒ String
Encrypt data.
-
#initialize(key, iv) ⇒ Aes256Cbc
constructor
Initialize cipher with key and IV.
Constructor Details
Instance Attribute Details
#iv ⇒ String (readonly)
Returns Initialization vector (16 bytes).
35 36 37 |
# File 'lib/omnizip/formats/rar/rar5/encryption/aes256_cbc.rb', line 35 def iv @iv end |
#key ⇒ String (readonly)
Returns AES-256 key (32 bytes).
32 33 34 |
# File 'lib/omnizip/formats/rar/rar5/encryption/aes256_cbc.rb', line 32 def key @key end |
Class Method Details
.generate_iv ⇒ String
Generate random IV
68 69 70 |
# File 'lib/omnizip/formats/rar/rar5/encryption/aes256_cbc.rb', line 68 def self.generate_iv SecureRandom.random_bytes(IV_SIZE) end |
Instance Method Details
#decrypt(ciphertext) ⇒ String
Decrypt data
61 62 63 |
# File 'lib/omnizip/formats/rar/rar5/encryption/aes256_cbc.rb', line 61 def decrypt(ciphertext) @cipher.decrypt(ciphertext) end |
#encrypt(plaintext) ⇒ String
Encrypt data
53 54 55 |
# File 'lib/omnizip/formats/rar/rar5/encryption/aes256_cbc.rb', line 53 def encrypt(plaintext) @cipher.encrypt(plaintext) end |