简体   繁体   中英

Decrypt text encrypted using openSSL in java

If generated RSA keys and encrypted text as below

$ openssl genrsa -out private.pem 1024
$ openssl rsa -in private.pem -out public.pem -outform PEM -pubout
$ echo 'too many secrets' > file.txt
$ openssl rsautl -encrypt -inkey public.pem -pubin -in file.txt -out file.ssl

Now I want to decrypt in in JAVA source code. IS there any way to do it?

Yes, our code does exactly this. We encrypt database encryption keys using the openssl tool and then decrypt them in Java using Java's built in Crypto package:

https://docs.oracle.com/javase/7/docs/api/javax/crypto/package-summary.html

I think this SO post might give you the information you need:

Java equivalent of an OpenSSL AES CBC encryption

Seems like good stuff here too:

Java decryption of an encrypted file with openssl aes 256 cbc

There should be multiple answers to this question to be had via Google or previous SO questions in addition to these. I think the basic idea is here in these posts. The trick will be getting everything right for whatever encryption parameters your using to encrypt. You seem to be using all of the defaults. We use the -aes-256-cbc option. If you can control what encryption parameters you can use, finding an answer might be eaiser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM