简体   繁体   English

在Java中解密使用OpenSSL加密的文本

[英]Decrypt text encrypted using openSSL in java

If generated RSA keys and encrypted text as below 如果生成如下所示的RSA密钥和加密的文本

$ 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. 现在我想用JAVA源代码解密。 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: 我们使用openssl工具对数据库加密密钥进行加密,然后使用Java的内置Crypto软件包在Java中对它们进行解密:

https://docs.oracle.com/javase/7/docs/api/javax/crypto/package-summary.html 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: 我认为这篇SO帖子可能会为您提供所需的信息:

Java equivalent of an OpenSSL AES CBC encryption Java等同于OpenSSL AES CBC加密

Seems like good stuff here too: 这里也似乎是好东西:

Java decryption of an encrypted file with openssl aes 256 cbc 使用OpenSSL AES 256 CBC对加密文件进行Java解密

There should be multiple answers to this question to be had via Google or previous SO questions in addition to these. 除了这些之外,还应该通过Google或以前的SO问题获得多个答案。 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. 我们使用-aes-256-cbc选项。 If you can control what encryption parameters you can use, finding an answer might be eaiser. 如果您可以控制可以使用的加密参数,那么寻找答案可能会很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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