加密机制

为保证数据的安全性,平台会对每个请求和响应进行加密。

接入方与平台需使用对称加密算法AES/ECB/PKCS5Padding,对请求体和响应体进行加密与解密,结果采用Base64 编码。

平台需要接入方提前提供128位AES密钥(Base64 编码格式)。

请求体

原始请求体各字段含义详见下方各API说明。

接入方:对原始请求体先使用AES密钥加密,再进行Base64编码。结果作为实际请求体中bizContent字段的值。发送实际请求体。

平台:对收到的实际请求体的bizContent字段的值先进行Base64解码,再使用AES密钥解密。结果即为原始请求体。

{
  "key_1": "value_1",
  "key_2": "value_2",
  "key_3": "value_3"
}

工具类示例

<?php

class AesUtils {

    public static function aesEncrypt(string $keyStr, string $plaintext): string {
        return base64_encode(openssl_encrypt($plaintext, 'AES-128-ECB', base64_decode($keyStr), OPENSSL_RAW_DATA));
    }

    public static function aesDecrypt(string $keyStr, string $ciphertext): string {
        return openssl_decrypt(base64_decode($ciphertext), 'AES-128-ECB', base64_decode($keyStr), OPENSSL_RAW_DATA);
    }
}

最后更新于