|
|
@@ -32,4 +32,19 @@ public class PrivateKeySigner implements Signer { |
|
|
|
throw new WxRuntimeException("无效的私钥", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String signMessage(byte[] message) { |
|
|
|
try { |
|
|
|
Signature sign = Signature.getInstance("SHA256withRSA"); |
|
|
|
sign.initSign(privateKey); |
|
|
|
sign.update(message); |
|
|
|
return Base64.getEncoder().encodeToString(sign.sign()); |
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
throw new WxRuntimeException("当前Java环境不支持SHA256withRSA", e); |
|
|
|
} catch (SignatureException e) { |
|
|
|
throw new WxRuntimeException("签名计算失败", e); |
|
|
|
} catch (InvalidKeyException e) { |
|
|
|
throw new WxRuntimeException("无效的私钥", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |