会PHP。还不会Java,奈何文档只有Java 代码demo
public static String decode(String message, String privateKey) throws KsMerchantApiException {
try {
if (KsStringUtils.isBlank(message) || KsStringUtils.isBlank(privateKey)) {
throw new KsMerchantApiException("decode param is blank");
}
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
byte[] key = Base64.decodeBase64(privateKey);
SecretKeySpec keySpec = new SecretKeySpec(key, KEY_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(new byte[16]));
return new String(cipher.doFinal(Base64.decodeBase64(message)), CHARSET);
} catch (Exception e) {
throw new KsMerchantApiException("decode message fail", e);
}
}
已经根据Java demo 写出了一个PHP版。只是拿实际参数怎么运行都是解析false
function decode($message, $privateKey)
{
// base64 反编码数据
$message = base64_decode($message);
// base64 反编码密钥
$key = base64_decode($privateKey);
// Iv向量我根据demo代码猜应该是反编码密钥后的前16位
$iv = substr($key, 0, 16);
// 只知道Java的加密是 采用AES加密。我PHP对应 aes-256-cbc? 不知道对不对
$result = openssl_decrypt($message, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
return $result;
}
可提供参数密钥,寻求相关大佬指教
补充文档地址: 文档地址
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…