ruby-gpgme
ruby-gpgme copied to clipboard
password vs passphrase
In the example below, I have tried password and passphrase. Neither seem to allow me to run my code without a openpgp box prompting for the passphrase, the following message:
Pinentry Mac "Please enter the passphrase to unlock the secret key for the OpenPGP certificate" What do I need to change to allow my code to run without the prompt? I know my password is correct in the code.
I have tried :
ctx = GPGME::Ctx.new :password=> 'password'
and this:
ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)
But both do not seem to work. Any advice is appreciated.
def self.passfunc(obj, uid_hint, passphrase_info, prev_was_bad, fd)
io = IO.for_fd(fd, 'w')
io.puts 'password'
io.flush
end
def self.decrypt_file(local_file, decrypted_file = nil)
# Set decrypted file path if one is not provided
decrypted_file = local_file.chomp(File.extname(local_file)) + ".csv" if decrypted_file == nil
encrypted_data = GPGME::Data.new(File.open(local_file))
# Set the password and GPG Key to decryption
ctx = GPGME::Ctx.new :password=> 'password'
# I have tried the passphrase call back
#ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)
#KEY= GPGME::Data.new(File.open("key.gpg"))
ctx.import_keys Rebal::Config::KEY
# Decrypt the data
decrypted = ctx.decrypt encrypted_data
decrypted.seek(0)
#Write the data to a file
File.write(decrypted_file, decrypted.read)
#return path
decrypted_file
end
In my experience you need to use GPG 1.x to not have to pin entry program activate. It's a feature of GPG 2 to force the pinentry program
This probably needs to be in the docs, seems like a common problem.
Dan
On 4 Feb 2014, at 23:20, yoshie902a [email protected] wrote:
In the example below, I have tried password and passphrase. Neither seem to allow me to run my code without a openpgp box prompting for the passphrase, the following message:
Pinentry Mac "Please enter the passphrase to unlock the secret key for the OpenPGP certificate" What do I need to change to allow my code to run without the prompt? I know my password is correct in the code.
I have tried : ctx = GPGME::Ctx.new :password=> 'password' and this: ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)
But both do not seem to work. Any advice is appreciated.
def self.passfunc(obj, uid_hint, passphrase_info, prev_was_bad, fd) io = IO.for_fd(fd, 'w') io.puts 'password' io.flush end
def self.decrypt_file(local_file, decrypted_file = nil) # Set decrypted file path if one is not provided decrypted_file = local_file.chomp(File.extname(local_file)) + ".csv" if decrypted_file == nil encrypted_data = GPGME::Data.new(File.open(local_file))
# Set the password and GPG Key to decryption ctx = GPGME::Ctx.new :password=> 'password' # I have tried the passphrase call back #ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc) #KEY= GPGME::Data.new(File.open("key.gpg")) ctx.import_keys Rebal::Config::KEY # Decrypt the data decrypted = ctx.decrypt encrypted_data decrypted.seek(0) #Write the data to a file File.write(decrypted_file, decrypted.read) #return path decrypted_file
end — Reply to this email directly or view it on GitHub.
-
What is the difference between password and passphrase in my example above?
-
Is there a way to use GPG2 and use code to prevent the pin entry box? I found this link... http://dilawarnotes.wordpress.com/2013/02/13/disable-gpg-gui-asking-for-paraphrase/ and it disables the pin entry, but I get an "GPGME::Error::BadPassphrase: Bad passphrase" error. What could be causing this?
Currently, I downgraded from GPG2 to GPG 1.4 and it seems to be working, but would love to understand how to get GPG2 to work.
Thanks
Unfortunately, you cannot pass passphrase programmatically with GPG 2.0. See #11. (GPG 2.1 has pinentry-mode option which simulates GPG 1.4 behavior, but it is still in development)