lib/AppleDecrypter.rb
def generate_key_encrypting_key(password, salt, iterations, debug_text=nil)
    # Key length in bytes, multiple by 8 for bits. Apple is using 16 (128-bit)
    key_size = 16
    generated_key = nil

    begin
      generated_key = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, key_size, OpenSSL::Digest::SHA256.new)
    rescue OpenSSL::Cipher::CipherError
      puts "Caught CipherError trying to generate PBKDF2 key"
      @logger.error("Apple Decrypter: #{debug_text} caught a CipherError while trying to generate PBKDF2 key.")
    end

    return generated_key
  end
## 
# This function calls PBKDF2 with Apple's settings to generate a key encrypting key. 
# It expects the +password+ as a String, the +salt+ as a binary String, and the number of 
# +iterations+ as an integer. It returns either nil or the generated key as a binary String. 
# It an error occurs, it will rescue a OpenSSL::Cipher::CipherError and log it.
This function calls PBKDF2 with Apple's settings to generate a key encrypting key.
This function calls PBKDF2 with Apple ' s settings to generate a key encrypting key .
def generate_key_encrypting_key(password, salt, iterations, debug_text=nil)
    key_size = 16
    generated_key = nil
    begin
      generated_key = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, key_size, OpenSSL::Digest::SHA256.new)
    rescue OpenSSL::Cipher::CipherError
      puts "Caught CipherError trying to generate PBKDF2 key"
      @logger.error("Apple Decrypter: #{debug_text} caught a CipherError while trying to generate PBKDF2 key.")
    end
    return generated_key
  end
def generate_key_encrypting_key ( password , salt , iterations , debug_text = nil ) key_size = 16 generated_key = nil begin generated_key = OpenSSL :: PKCS5 . pbkdf2_hmac ( password , salt , iterations , key_size , OpenSSL :: Digest :: SHA256 . new ) rescue OpenSSL :: Cipher :: CipherError puts "Caught CipherError trying to generate PBKDF2 key" @logger . error ( "Apple Decrypter: #{debug_text} caught a CipherError while trying to generate PBKDF2 key." ) end return generated_key end
This function calls PBKDF2 with Apple's settings to generate a key encrypting key.
This function calls PBKDF2 with Apple ' s settings to generate a key encrypting key .
# Key length in bytes, multiple by 8 for bits. Apple is using 16 (128-bit)
password
salt
iterations
debug_text