Class: Omnizip::Formats::Rar::Rar5::Encryption::KeyDerivation
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Rar5::Encryption::KeyDerivation
- Defined in:
- lib/omnizip/formats/rar/rar5/encryption/key_derivation.rb
Overview
RAR5 password-based key derivation
RAR5 uses PBKDF2-HMAC-SHA256 for key derivation, which is more secure than 7-Zip's iterative SHA-256 approach.
The process:
- Generate random salt (16 bytes)
- Apply PBKDF2-HMAC-SHA256 with configurable iterations
- Derive 32-byte AES-256 key
Constant Summary collapse
- DEFAULT_ITERATIONS =
Default PBKDF2 iterations (262,144 = 2^18) This provides good security while maintaining reasonable performance
262_144- MIN_ITERATIONS =
Minimum iterations (2^16 = 65,536)
65_536- MAX_ITERATIONS =
Maximum iterations (2^20 = 1,048,576)
1_048_576- SALT_SIZE =
Salt size (16 bytes)
16- KEY_SIZE =
Key size (32 bytes for AES-256)
32
Class Method Summary collapse
-
.derive_key(password, salt, iterations = DEFAULT_ITERATIONS) ⇒ String
Derive AES-256 key from password using PBKDF2-HMAC-SHA256.
-
.generate_salt ⇒ String
Generate random salt.
Class Method Details
.derive_key(password, salt, iterations = DEFAULT_ITERATIONS) ⇒ String
Derive AES-256 key from password using PBKDF2-HMAC-SHA256
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/omnizip/formats/rar/rar5/encryption/key_derivation.rb', line 48 def self.derive_key(password, salt, iterations = DEFAULT_ITERATIONS) validate_inputs(password, salt, iterations) # PBKDF2-HMAC-SHA256 OpenSSL::PKCS5.pbkdf2_hmac( password, salt, iterations, KEY_SIZE, OpenSSL::Digest.new("SHA256"), ) end |
.generate_salt ⇒ String
Generate random salt
64 65 66 |
# File 'lib/omnizip/formats/rar/rar5/encryption/key_derivation.rb', line 64 def self.generate_salt SecureRandom.random_bytes(SALT_SIZE) end |