我先加密一条消息,然后再解密.要点是:https://gist.github.com/2489899.
我必须将这些密钥存储在xml方案中,因为消息也应该也可以在c#中解密. (这只是我的程序与数据库的“摘要”,依此类推).但我总是得到异常:
javax.crypto.BadPaddingException: Data must start with zero
at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:308)
at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:255)
at com.sun.crypto.provider.RSACipher.a(DashoA13*..)
at com.sun.crypto.provider.RSACipher.engineDoFinal(DashoA13*..)
at javax.crypto.Cipher.doFinal(DashoA13*..)
at Main.decrypt(Main.java:50)
at Main.main(Main.java:24)
解决方法:
很简单,您的RSAPrivateCrtKeySpec构造函数调用使用了不正确的参数顺序.