简体   繁体   English

RSA Java:私钥不能用于加密

[英]RSA Java: Private Key cannot be used to encrypt

I am using RSA Algorithm for encryption and decryption of files.我正在使用 RSA 算法对文件进行加密和解密。 Currently, I have implemented the code on my local machine (Windows) and used private key to encrypt the file and public key to decrypt the same and it worked fine.目前,我已经在我的本地机器(Windows)上实现了代码,并使用私钥来加密文件和公钥来解密它,它工作正常。

However, when I deployed my application to AIX machine than same approach thrown an exception that:但是,当我将我的应用程序部署到 AIX 机器时,同样的方法引发了一个异常:

Private Key cannot be used to encrypt

I then checked in my logs that my java on windows machine is using sun.security.rsa security provider and Java on AIX is using com.ibm.crypto.provider I then checked in my logs that my java on windows machine is using sun.security.rsa security provider and Java on AIX is using com.ibm.crypto.provider

When I further surfed on internet I got to know that IBM does not allow in RSA to encrypt using private key.当我进一步上网时,我知道 IBM 不允许 RSA 使用私钥进行加密。

Now the problem is that I do have to use private key for encrypton, but it requires to install or somehow embedd new security provider in my AIX Machine ie sun.security.rsa .现在的问题是我必须使用私钥进行加密,但它需要在我的 AIX 机器中安装或以某种方式嵌入新的安全提供程序,即sun.security.rsa

Can I do it in my existing code directly?我可以直接在现有代码中执行此操作吗? or can I somehow use private key for encryption using ibm package?或者我可以使用 ibm package 以某种方式使用私钥进行加密吗? or any other way around?或任何其他方式? please help!请帮忙!

I have resolved the issue by using different JCE ie BouncyCastle instead of IBM JCE.我已经通过使用不同的 JCE(即 BouncyCastle 而不是 IBM JCE)解决了这个问题。

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

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