Wechatpay-Serial 加密示例代码中公钥如何传入
如下分账i请求接口中敏感字段加密时如何设置和传入公钥参数??
public static String rsaEncryptOAEP(String message, X509Certificate certificate)
2throws IllegalBlockSizeException, IOException {
3 try {
4 Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
5 cipher.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey());
6
7 byte[] data = message.getBytes("utf-8");
8 byte[] cipherdata = cipher.doFinal(data);
9 return Base64.getEncoder().encodeToString(cipherdata);
10 } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
11 throw new RuntimeException("当前Java环境不支持RSA v1.5/OAEP", e);
12 } catch (InvalidKeyException e) {
13 throw new IllegalArgumentException("无效的证书", e);
14 } catch (IllegalBlockSizeException | BadPaddingException e) {
15 throw new IllegalBlockSizeException("加密原串的长度不能超过214字节");
16 }
17}