Forum Stats

  • 3,768,511 Users
  • 2,252,802 Discussions
  • 7,874,602 Comments

Discussions

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

Namsha
Namsha Member Posts: 2
edited Jun 8, 2017 4:46AM in Java User Groups Discussions

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

Answers