类 DashScopeEncryptionUtils

java.lang.Object
io.agentscope.core.model.DashScopeEncryptionUtils

public final class DashScopeEncryptionUtils extends Object
Encryption utilities for secure DashScope API access.

This class provides encryption functionality for DashScope API calls using:

  • AES-GCM encryption for request/response data
  • RSA public key encryption for AES key exchange

This implementation follows Aliyun's encryption protocol requirements for secure cloud model inference, supporting TLS encryption and token-based authentication.

  • 方法详细资料

    • generateAesSecretKey

      public static SecretKey generateAesSecretKey()
      Generate a new AES secret key for encryption.
      返回:
      a new AES-256 secret key
      抛出:
      DashScopeEncryptionUtils.EncryptionException - if key generation fails
    • generateIv

      public static byte[] generateIv()
      Generate a unique initialization vector (IV) for AES-GCM encryption.
      返回:
      a random 12-byte IV
    • encryptWithAes

      public static String encryptWithAes(SecretKey secretKey, byte[] iv, String plaintext)
      Encrypt data using AES-GCM.
      参数:
      secretKey - the AES secret key
      iv - the initialization vector
      plaintext - the plaintext data to encrypt
      返回:
      Base64-encoded encrypted data
      抛出:
      DashScopeEncryptionUtils.EncryptionException - if encryption fails
    • decryptWithAes

      public static String decryptWithAes(SecretKey secretKey, byte[] iv, String encryptedData)
      Decrypt data using AES-GCM.
      参数:
      secretKey - the AES secret key
      iv - the initialization vector
      encryptedData - Base64-encoded encrypted data
      返回:
      the decrypted plaintext
      抛出:
      DashScopeEncryptionUtils.EncryptionException - if decryption fails
    • encryptAesKeyWithRsa

      public static String encryptAesKeyWithRsa(SecretKey aesSecretKey, String publicKeyBase64)
      Encrypt an AES secret key using RSA public key.
      参数:
      aesSecretKey - the AES secret key to encrypt
      publicKeyBase64 - Base64-encoded RSA public key
      返回:
      Base64-encoded encrypted AES key
      抛出:
      DashScopeEncryptionUtils.EncryptionException - if encryption fails