对于支付 API,我需要使用 SHA-512 对字符串(请求有效负载)进行哈希处理,根据文档使用“RSA”对其进行签名。
- 使用 SHA512 算法散列有效载荷字符串(支付指令)。
- 使用 RSA 算法和签名证书私钥对散列的有效负载字符串进行签名。
- Base64 编码签名哈希
第1步和第3步我没有问题。第2步是问题。支持向我发送了一个 java 示例,但我们不运行 java,如果可能的话,我想在 OpenSSL 中执行此操作。
private static String createSignature(String stringToBeSigned, PrivateKey privateKey) {
try {
byte[] hashString = hashString(stringToBeSigned);
Signature sign = Signature.getInstance("SHA512withRSA");
sign.initSign(privateKey);
sign.update(hashString);
byte[] signature = sign.sign();
return Base64.getEncoder().encodeToString(signature);
} catch (Exception e) {
throw new RuntimeException("Could not create signed payout request.", e);
}
}
private static byte[] hashString(String stringToBeHashed) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-512");
return digest.digest(stringToBeHashed.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
提供了密钥。如何使用 OpenSSL 找到“SHA512withRSA”对应的内容?