Forum Stats

  • 3,727,533 Users
  • 2,245,406 Discussions


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

Namsha Member Posts: 2


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:

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


Sign In or Register to comment.