Skip to Main Content

Java User Groups

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Not able to decrypt the file generated with Java code using RSA encryption

NamshaJun 8 2017 — edited Jun 8 2017

Hi,

My issue is regarding the RSA encryption and Decryption.

Our product is encrypting and generating a file(large in size) with extension '.DAT' using RSA through JAva code..... where in we are providing public key generated using below link:

https://blogs.oracle.com/wssfc/how-to-generate-pgp-keys-using-gpg-145-on-linux

Java Code snippet :

cipher.init(Cipher.ENCRYPT_MODE, pubKey);

FileOutputStream fos = new FileOutputStream(ciphertextFile);

CipherOutputStream cos = new CipherOutputStream(fos, cipher);

And through Javacode we are able to decrypt the encrypted '.DAT' file using private key.

However, if I try to decrypt the same file '.DAT' file with private key using command line as below :

gpg --output doc --decrypt doc.DAT

its giving below error:

gpg: no valid OpenPGP data found.

gpg: decrypt_message failed: Unknown system error

Now if I tried to encrypt the file using the tool with same public key and then decrypt the file with same private key its working fine.

Please note in this case the file extension is .gpg and not .DAT

Comments

karianna

Can a moderator please move this to the Java cryptography / security forum?

@OP - What happens if you save that .DAT file as .gpg and use the command line tool.  Does that work?

Namsha

Hi Karianna,

Still its giving the same error.

gpg: no valid OpenPGP data found.

gpg: decrypt_message failed: Unknown system error

1 - 2

Post Details

Added on Jun 8 2017
2 comments
882 views