java.lang.Object
com.alibaba.dashscope.applications.agentstudio.utils.EncryptionUtils

public class EncryptionUtils extends Object
RSA/AES helpers for encrypted AgentStudio requests and responses.
  • Constructor Details

    • EncryptionUtils

      public EncryptionUtils()
  • Method Details

    • RSAEncrypt

      public static String RSAEncrypt(String input, String base64AESEncryptKey) throws ApiException
      RSA encrypt the input string, return the base64 encoded cipher text.
      Parameters:
      input - The string to be encrypted.
      base64AESEncryptKey - The base64 encoded AES encrypt key.
      Returns:
      The base64 encoded cipher of the input.
      Throws:
      ApiException
    • generateAESKey

      public static SecretKey generateAESKey()
      Generate a AES secret key.
      Returns:
      The AES SecretKey.
    • AESEncrypt

      public static String AESEncrypt(String input, SecretKey secretKey, byte[] iv) throws ApiException
      AES encrypt input, and output base64 encoded cipher text.
      Parameters:
      input - The input string
      secretKey - The AES secret key.
      iv - The Initialization Vector (IV) to augment the encryption.
      Returns:
      The base64 encoded cipher text.
      Throws:
      ApiException
    • AESEncrypt

      public static String AESEncrypt(byte[] input, SecretKey secretKey, byte[] iv) throws ApiException
      AES encrypt input, and output base64 encoded cipher text.
      Parameters:
      input - The input bytes to encrypt.
      secretKey - The AES secret key.
      iv - The Initialization Vector (IV) to augment the encryption.
      Returns:
      The base64 encoded cipher text.
      Throws:
      ApiException
    • AESDecrypt

      public static String AESDecrypt(String cipherText, SecretKey secretKey, byte[] iv) throws ApiException
      AES decrypting encrypted cipher text.
      Parameters:
      cipherText - The cipher text to be decrypted.
      secretKey - The secret key to use.
      iv - The Initialization Vector (IV) of the encryption.
      Returns:
      The plain text of cipher text.
      Throws:
      ApiException
    • generateEncryptionConfig

      public static EncryptionConfig generateEncryptionConfig(String apiKey) throws ApiException, NoApiKeyException
      Generate a EncryptionConfig.
      Throws:
      ApiException
      NoApiKeyException
    • generateEncryptionConfig

      public static EncryptionConfig generateEncryptionConfig(String apiKey, String baseHttpUrl) throws ApiException, NoApiKeyException
      Generate a EncryptionConfig, fetching the public key from the given base URL.
      Throws:
      ApiException
      NoApiKeyException