I have some java code to encrypt a file using some public key. I have public key file. File encrypted successfully. Now I want to decrypt the encrypted file to get the original file. For that one I need private key & password. I don't have private key & password. I am using PGP encryption algorithim. Please guide me how to genarate public key file & private key file & password. So that I can test the code with one file encryption & decryption in my side. I am spending lot of time on the net. Bit difficult for me to understand all those.
You indicated you have a public key.
Is this your own key or is this someone elses who you intend to send the encrypted file to?
I assume it must be someone elses because if it was your own key you should already know the password and be able to generate the private key for it using PGP desktop or numerous free utilities to generate key pairs.
If my assumption is right, the easiest way to test your routine is to encrypt the file to TWO public keys. The public key of the person you intend to send the file to as well as your own public key. This way, you will both be able to decrypt the file.
You are probably already using encryptedDataGenerator.addMethod(PGPPublicKey) to add the public key you have.
Just do this a second time with your own key as well.
Then the file will be encrypted to both keys allowing both people to decrypt it.