我需要某人的帮助。 在我的android手机中,我创建了公钥(用于加密文件)和私钥来解密。我将它们保存在2个文件中。当我通过android解密时没关系。但是,当我复制私钥文件,并用它在我的电脑(JAVA)解密,我得到异常:使用私钥解密文件(RSA)
at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
at sun.security.rsa.RSAPadding.unpad(Unknown Source)
at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356)
at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at com.molisy.decryptfile.Main.RSADecrypt(Main.java:193)
at com.molisy.decryptfile.Main$2.actionPerformed(Main.java:309)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
我不知道如何解决。但是,私钥文件的价值是不一样的,如果我打印它在我的android和我的电脑。 在我的Android应用程序中:OpenSSLRSAPrivateKey{modulus=a9a141d6ef0050e27f00ec381f2fcfeb47781dcfb14f9b3eb378bd361b92b6da7feb8f2be7466314794d7543eb99c818d260d48b898c9995db3a3af76b23013ff935f77b8a89edcbd9d16a583b60591e55f7cb8271fa4cfae53fd759f3d8e1b522485e2cf29e89034223329322b4357c84fc848348b004136d6d360f8c9a70cb,privateExponent=7eaff2ee455da50b23f35a78a7c21bb50a9189223eb8c7a7527ed04182e2563265eb55e862384d73530d28916b7a54d944f610878e5935b39821ab3c720598be28d747de099ff8fac6558f235b983815efc61cbc574be39d97dc7ac57e6cf82161f4301dfe777c3c33c58d7c75f581de5cc0db83b079de7d79864a6189667171,
和我的java应用程序:[email protected]
为什么它是如此的不同。以及如何修复
不要在公共场所发布您的私钥模数。 – hexafraction 2014-09-24 11:32:14
@hexafraction更准确地说,不要将你的私人指数放在公共场所。输出不同的原因是因为'OpenSSLRSAPrivateKey'覆盖了Object.toString()和'RSAPrivateKeyImpl'。 – 2014-09-24 11:35:41
如果pc和android上的key不一样,那么你知道理由。找出为什么不一样。 – 2014-09-24 11:35:58