Class: Omnizip::Formats::Rar::Rar5::Encryption::EncryptionHeader

Inherits:
Lutaml::Model::Serializable
  • Object
show all
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

Examples:

Create encryption header

header = EncryptionHeader.new(
  version: 0,
  kdf_iterations: 262_144,
  salt: salt,
  iv: iv,
  check_value: check
)

Instance Method Summary collapse

Instance Method Details

#iv_binaryString

Get IV as binary

Returns:

  • (String)

    16-byte binary IV



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

Parameters:

  • binary_iv (String)

    16-byte binary IV



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_binaryString

Get salt as binary

Returns:

  • (String)

    16-byte binary salt



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

Parameters:

  • binary_salt (String)

    16-byte binary salt



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

Raises:

  • (ArgumentError)

    If validation fails



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.message}"
end