Module: Zip::AESEncryption

Included in:
AESDecrypter, AESEncrypter
Defined in:
lib/zip/crypto/aes_encryption.rb

Overview

:nodoc:

Constant Summary collapse

VERIFIER_LENGTH =
2
BLOCK_SIZE =
16
AUTHENTICATION_CODE_LENGTH =
10
VERSION_AE_1 =
0x01
VERSION_AE_2 =
0x02
VERSIONS =
[
  VERSION_AE_1,
  VERSION_AE_2
].freeze
STRENGTH_128_BIT =
0x01
STRENGTH_192_BIT =
0x02
STRENGTH_256_BIT =
0x03
STRENGTHS =
[
  STRENGTH_128_BIT,
  STRENGTH_192_BIT,
  STRENGTH_256_BIT
].freeze
BITS =
{
  STRENGTH_128_BIT => 128,
  STRENGTH_192_BIT => 192,
  STRENGTH_256_BIT => 256
}.freeze
KEY_LENGTHS =
{
  STRENGTH_128_BIT => 16,
  STRENGTH_192_BIT => 24,
  STRENGTH_256_BIT => 32
}.freeze
SALT_LENGTHS =
{
  STRENGTH_128_BIT => 8,
  STRENGTH_192_BIT => 12,
  STRENGTH_256_BIT => 16
}.freeze

Instance Method Summary collapse

Instance Method Details

#gp_flagsObject



64
65
66
# File 'lib/zip/crypto/aes_encryption.rb', line 64

def gp_flags
  0x0001
end

#header_bytesizeObject



60
61
62
# File 'lib/zip/crypto/aes_encryption.rb', line 60

def header_bytesize
  @salt_length + VERIFIER_LENGTH
end

#initialize(password, strength) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zip/crypto/aes_encryption.rb', line 47

def initialize(password, strength)
  # Loaded here rather than at the top of the file so that `require 'zip'`
  # does not pull in openssl. Only AES-encrypted archives need it, and it
  # is the single largest cost of loading this library.
  require 'openssl'

  @password = password
  @strength = strength
  @bits = BITS[@strength]
  @key_length = KEY_LENGTHS[@strength]
  @salt_length = SALT_LENGTHS[@strength]
end