Class: Omnizip::Formats::Rar::Rar5::Encryption::EncryptionHeader
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Omnizip::Formats::Rar::Rar5::Encryption::EncryptionHeader
- Defined in:
- lib/omnizip/formats/rar/rar5/encryption/encryption_header.rb
Overview
RAR5 encryption header
This model stores encryption parameters needed for password verification and decryption. The header is written at the beginning of encrypted archive sections.
RAR5 encryption header contains:
- Version (always 0 for AES-256)
- KDF iteration count
- Salt for key derivation
- IV for AES-CBC
- Check value for password verification
Instance Method Summary collapse
-
#iv_binary ⇒ String
Get IV as binary.
-
#iv_binary=(binary_iv) ⇒ Object
Set IV from binary.
-
#salt_binary ⇒ String
Get salt as binary.
-
#salt_binary=(binary_salt) ⇒ Object
Set salt from binary.
-
#validate! ⇒ Object
Validate header.
Instance Method Details
#iv_binary ⇒ String
Get IV as binary
92 93 94 |
# File 'lib/omnizip/formats/rar/rar5/encryption/encryption_header.rb', line 92 def iv_binary Base64.strict_decode64(iv) end |
#iv_binary=(binary_iv) ⇒ Object
Set IV from binary
106 107 108 |
# File 'lib/omnizip/formats/rar/rar5/encryption/encryption_header.rb', line 106 def iv_binary=(binary_iv) self.iv = Base64.strict_encode64(binary_iv) end |
#salt_binary ⇒ String
Get salt as binary
85 86 87 |
# File 'lib/omnizip/formats/rar/rar5/encryption/encryption_header.rb', line 85 def salt_binary Base64.strict_decode64(salt) end |
#salt_binary=(binary_salt) ⇒ Object
Set salt from binary
99 100 101 |
# File 'lib/omnizip/formats/rar/rar5/encryption/encryption_header.rb', line 99 def salt_binary=(binary_salt) self.salt = Base64.strict_encode64(binary_salt) end |
#validate! ⇒ Object
Validate header
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/omnizip/formats/rar/rar5/encryption/encryption_header.rb', line 57 def validate! if version != 0 raise ArgumentError, "Only AES-256 (version 0) is supported" end if kdf_iterations < 65_536 || kdf_iterations > 1_048_576 raise ArgumentError, "KDF iterations must be between 65,536 and 1,048,576" end # Validate salt (base64 decoded should be 16 bytes) decoded_salt = Base64.strict_decode64(salt) if decoded_salt.bytesize != 16 raise ArgumentError, "Salt must be 16 bytes" end # Validate IV (base64 decoded should be 16 bytes) decoded_iv = Base64.strict_decode64(iv) if decoded_iv.bytesize != 16 raise ArgumentError, "IV must be 16 bytes" end rescue ArgumentError => e raise ArgumentError, "Invalid encryption header: #{e.}" end |