Skip to content

加密说明

加密方式

根据对接协议,支持以下两种加密方式:

方式一:纯 AES 加密

  • 算法:AES/ECB/PKCS5Padding
  • 密钥长度:256位(32字节)
  • 编码方式:Base64

方式二:RSA + AES 混合加密

  • RSA:用于加密 AES 密钥
  • AES:用于加密业务数据
  • 编码方式:Base64

AES 加密示例(Java)

java
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class AESUtil {
    public static String encrypt(String content, String key) throws Exception {
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] encrypted = cipher.doFinal(content.getBytes("UTF-8"));
        return Base64.getEncoder().encodeToString(encrypted);
    }
}

注意事项

具体加密方式以对接时协商为准,本文档提供常用加密方案参考。