Class: Zip::AESDecrypter
- Includes:
- AESEncryption
- Defined in:
- lib/zip/crypto/aes_encryption.rb
Overview
:nodoc:
Constant Summary
Constants included from AESEncryption
Zip::AESEncryption::AUTHENTICATION_CODE_LENGTH, Zip::AESEncryption::BITS, Zip::AESEncryption::BLOCK_SIZE, Zip::AESEncryption::KEY_LENGTHS, Zip::AESEncryption::SALT_LENGTHS, Zip::AESEncryption::STRENGTHS, Zip::AESEncryption::STRENGTH_128_BIT, Zip::AESEncryption::STRENGTH_192_BIT, Zip::AESEncryption::STRENGTH_256_BIT, Zip::AESEncryption::VERIFIER_LENGTH, Zip::AESEncryption::VERSIONS, Zip::AESEncryption::VERSION_AE_1, Zip::AESEncryption::VERSION_AE_2
Instance Method Summary collapse
Methods included from AESEncryption
#gp_flags, #header_bytesize, #initialize
Instance Method Details
#check_integrity!(io) ⇒ Object
208 209 210 211 |
# File 'lib/zip/crypto/aes_encryption.rb', line 208 def check_integrity!(io) auth_code = io.read(AUTHENTICATION_CODE_LENGTH) raise Error, 'Integrity fault' if @hmac.digest[0...AUTHENTICATION_CODE_LENGTH] != auth_code end |
#decrypt(encrypted_data) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/zip/crypto/aes_encryption.rb', line 171 def decrypt(encrypted_data) @hmac.update(encrypted_data) idx = 0 decrypted_data = +'' amount_to_read = encrypted_data.size while amount_to_read.positive? @cipher.iv = [@counter + 1].pack('Vx12') begin_index = BLOCK_SIZE * idx end_index = begin_index + [BLOCK_SIZE, amount_to_read].min decrypted_data << @cipher.update(encrypted_data[begin_index...end_index]) amount_to_read -= BLOCK_SIZE @counter += 1 idx += 1 end # JRuby requires finalization of the cipher. This is a bug, as noted in # jruby/jruby-openssl#182 and jruby/jruby-openssl#183. decrypted_data << @cipher.final if defined?(JRUBY_VERSION) decrypted_data end |
#reset!(header) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/zip/crypto/aes_encryption.rb', line 194 def reset!(header) salt = header[0...@salt_length] pwd_verify = header[-VERIFIER_LENGTH..] enc_key, enc_hmac_key, enc_pwd_verify = derive_keys(salt) raise Error, 'Bad password' if enc_pwd_verify != pwd_verify @counter = 0 @cipher = OpenSSL::Cipher::AES.new(@bits, :CTR) @cipher.decrypt @cipher.key = enc_key @hmac = OpenSSL::HMAC.new(enc_hmac_key, OpenSSL::Digest.new('SHA1')) end |