lib/AppleDecrypter.rb
def decrypt_with_password(password, salt, iterations, key, iv, tag, data, debug_text=nil)


    # Create the key with our password
    @logger.debug("Apple Decrypter: #{debug_text} Attempting decryption.")

    # Create variables to track our generated and unwrapped keys between blocks
    decrypt_result = false
    plainext = false

    # Generate the key-encrypting key from the user's password
    generated_key = generate_key_encrypting_key(password, salt, iterations)

    # Unwrap the key
    unwrapped_key = aes_key_unwrap(key, generated_key) if generated_key

    # Decrypt the content only if we have a key
    plaintext = aes_gcm_decrypt(unwrapped_key, iv, tag, data, debug_text) if unwrapped_key

    if plaintext
      decrypt_result = { plaintext: plaintext, password: password }
      @logger.debug("Apple Decrypter: #{debug_text} generated a decrypt")
    end

    return decrypt_result
  end
##
# This function attempts to decrypt the note with a specified password.
# It expects a +password+ as a normal String, a +salt+ as a binary String, the number of +iterations+ as an Integer, 
# a +key+ representing the wrapped key as a binary String, an +iv+ as a binary String, a +tag+ as a binary String, 
# the +data+ to be decrypted as a binary String, and the +item+ being decrypted as an Object to help with debugging. 
# This starts by unwrapping the +wrapped_key+ using the given +password+ by computing the PBDKF2 with the given +salt+ and +iterations+.
# With the unwrapped key, we can then use the +iv+ to decrypt the +data+ and authenticate it with the +tag+.
This function attempts to decrypt the note with a specified password.
This function attempts to decrypt the note with a specified password .
def decrypt_with_password(password, salt, iterations, key, iv, tag, data, debug_text=nil)
    @logger.debug("Apple Decrypter: #{debug_text} Attempting decryption.")
    decrypt_result = false
    plainext = false
    generated_key = generate_key_encrypting_key(password, salt, iterations)
    unwrapped_key = aes_key_unwrap(key, generated_key) if generated_key
    plaintext = aes_gcm_decrypt(unwrapped_key, iv, tag, data, debug_text) if unwrapped_key
    if plaintext
      decrypt_result = { plaintext: plaintext, password: password }
      @logger.debug("Apple Decrypter: #{debug_text} generated a decrypt")
    end
    return decrypt_result
  end
def decrypt_with_password ( password , salt , iterations , key , iv , tag , data , debug_text = nil ) @logger . debug ( "Apple Decrypter: #{debug_text} Attempting decryption." ) decrypt_result = false plainext = false generated_key = generate_key_encrypting_key ( password , salt , iterations ) unwrapped_key = aes_key_unwrap ( key , generated_key ) if generated_key plaintext = aes_gcm_decrypt ( unwrapped_key , iv , tag , data , debug_text ) if unwrapped_key if plaintext decrypt_result = { plaintext : plaintext , password : password } @logger . debug ( "Apple Decrypter: #{debug_text} generated a decrypt" ) end return decrypt_result end
This function attempts to decrypt the note with a specified password.
This function attempts to decrypt the note with a specified password .
# Create the key with our password # Create variables to track our generated and unwrapped keys between blocks # Generate the key-encrypting key from the user's password # Unwrap the key # Decrypt the content only if we have a key
password
salt
iterations
key
iv
tag
data
debug_text