收藏
回答

JSAPI支付生成prepay_id后支付验签失败?

Map<String, String> jsapiPayParam = new HashMap<>();
jsapiPayParam.put("appId", PayUtils.APP_ID);
jsapiPayParam.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
jsapiPayParam.put("nonceStr", UUID.randomUUID().toString());//随机字符串
jsapiPayParam.put("package", "prepay_id=" + resultMap.get("prepay_id"));
jsapiPayParam.put("signType", "RSA");
String plainText = jsapiPayParam.get("appId")+"\n"
                 + jsapiPayParam.get("timeStamp")+"\n"
                 + jsapiPayParam.get("nonceStr")+"\n"
                 + jsapiPayParam.get("package");
String cipherText = RsaCryptoUtil.encryptOAEP(plainText,verifier.getValidCertificate());
jsapiPayParam.put("paySign", cipherText);


java.lang.NullPointerException

at com.wechat.pay.contrib.apache.httpclient.util.RsaCryptoUtil.encryptOAEP(RsaCryptoUtil.java:24)

请问为什么会报空指针啊这里?


public static String encryptOAEP(String message, X509Certificate certificate) throws IllegalBlockSizeException {
    try {
        Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
        cipher.init(1, certificate.getPublicKey());
        byte[] data = message.getBytes(StandardCharsets.UTF_8);
        byte[] ciphertext = cipher.doFinal(data);
        return Base64.getEncoder().encodeToString(ciphertext);
    } catch (NoSuchPaddingException | NoSuchAlgorithmException var5) {
        throw new RuntimeException("当前Java环境不支持RSA v1.5/OAEP", var5);
    } catch (InvalidKeyException var6) {
        throw new IllegalArgumentException("无效的证书", var6);
    } catch (BadPaddingException | IllegalBlockSizeException var7) {
        throw new IllegalBlockSizeException("加密原串的长度不能超过214字节");
    }
}


at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容