Class: Omnizip::Crypto::Aes256
- Inherits:
-
Object
- Object
- Omnizip::Crypto::Aes256
- Includes:
- Constants
- Defined in:
- lib/omnizip/crypto/aes256.rb,
lib/omnizip/crypto/aes256/cipher.rb,
lib/omnizip/crypto/aes256/constants.rb,
lib/omnizip/crypto/aes256/key_derivation.rb
Overview
AES-256 encryption for 7-Zip archives
Implements 7-Zip's AES-256-CBC encryption with:
- Password-based key derivation (SHA-256)
- Configurable salt and cycles
- CBC mode with IV
This follows 7-Zip's encryption specification.
Defined Under Namespace
Modules: Constants Classes: Cipher, KeyDerivation
Constant Summary
Constants included from Constants
Constants::BLOCK_SIZE, Constants::DEFAULT_CYCLES_POWER, Constants::IV_SIZE, Constants::KEY_SIZE, Constants::MAX_CYCLES_POWER, Constants::MIN_CYCLES_POWER, Constants::SALT_SIZE, Constants::SALT_SIZE_MAX
Class Method Summary collapse
-
.decrypt(encrypted_data, password, salt, iv, cycles_power) ⇒ String
Decrypt data with AES-256.
-
.encrypt(data, password, options = {}) ⇒ Hash
Encrypt data with AES-256.
-
.generate_iv ⇒ String
Generate random IV.
-
.generate_salt(size = SALT_SIZE) ⇒ String
Generate random salt.
Class Method Details
.decrypt(encrypted_data, password, salt, iv, cycles_power) ⇒ String
Decrypt data with AES-256
79 80 81 82 83 84 |
# File 'lib/omnizip/crypto/aes256.rb', line 79 def self.decrypt(encrypted_data, password, salt, iv, cycles_power) key = KeyDerivation.derive_key(password, salt, cycles_power) cipher = Cipher.new(key, iv) cipher.decrypt(encrypted_data) end |
.encrypt(data, password, options = {}) ⇒ Hash
Encrypt data with AES-256
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/omnizip/crypto/aes256.rb', line 53 def self.encrypt(data, password, = {}) salt = [:salt] || generate_salt iv = [:iv] || generate_iv cycles_power = [:num_cycles_power] || DEFAULT_CYCLES_POWER key = KeyDerivation.derive_key(password, salt, cycles_power) cipher = Cipher.new(key, iv) encrypted_data = cipher.encrypt(data) { data: encrypted_data, salt: salt, iv: iv, cycles_power: cycles_power, } end |
.generate_iv ⇒ String
Generate random IV
97 98 99 |
# File 'lib/omnizip/crypto/aes256.rb', line 97 def self.generate_iv OpenSSL::Random.random_bytes(IV_SIZE) end |
.generate_salt(size = SALT_SIZE) ⇒ String
Generate random salt
90 91 92 |
# File 'lib/omnizip/crypto/aes256.rb', line 90 def self.generate_salt(size = SALT_SIZE) OpenSSL::Random.random_bytes(size) end |