BadPaddingException: Decryption error

  1. 使用golang做rsa加密,java解密出现点问题

  public static byte[] rsaDecrypt(String cryptograph, String private_key) throws Exception {
    BASE64Decoder b64d = new BASE64Decoder();
    byte[] keyByte = b64d.decodeBuffer(private_key);
    PKCS8EncodedKeySpec s8ek = new PKCS8EncodedKeySpec(keyByte);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    PrivateKey privateKey = keyFactory.generatePrivate(s8ek);
    Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA1AndMGF1Padding");
    cipher.init(2, privateKey);
    BASE64Decoder decoder = new BASE64Decoder();
    byte[] b1 = decoder.decodeBuffer(cryptograph);
    return cipher.doFinal(b1);
  }
func RsaEncrypt(data string) (string, error) {
    encrypt, err := rsa.EncryptOAEP(sha1.New(), rand.Reader, publicKey, []byte(data), []byte(""))
    if err != nil {
        return "", err
    }
    return base64.StdEncoding.EncodeToString(encrypt), nil
}

报错信息:

javax.crypto.BadPaddingException: Decryption error
阅读 15.6k
1 个回答
✓ 已被采纳新手上路,请多包涵

临时犯傻! 用的公钥和私钥不是一对  已解决

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏