Class EncryptionUtils
java.lang.Object
com.alibaba.dashscope.applications.agentstudio.utils.EncryptionUtils
RSA/AES helpers for encrypted AgentStudio requests and responses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringAESDecrypt(String cipherText, SecretKey secretKey, byte[] iv) AES decrypting encrypted cipher text.static StringAESEncrypt(byte[] input, SecretKey secretKey, byte[] iv) AES encrypt input, and output base64 encoded cipher text.static StringAESEncrypt(String input, SecretKey secretKey, byte[] iv) AES encrypt input, and output base64 encoded cipher text.static SecretKeyGenerate a AES secret key.static EncryptionConfiggenerateEncryptionConfig(String apiKey) Generate a EncryptionConfig.static EncryptionConfiggenerateEncryptionConfig(String apiKey, String baseHttpUrl) Generate a EncryptionConfig, fetching the public key from the given base URL.static StringRSAEncrypt(String input, String base64AESEncryptKey) RSA encrypt the input string, return the base64 encoded cipher text.
-
Constructor Details
-
EncryptionUtils
public EncryptionUtils()
-
-
Method Details
-
RSAEncrypt
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
Generate a AES secret key.- Returns:
- The AES SecretKey.
-
AESEncrypt
AES encrypt input, and output base64 encoded cipher text.- Parameters:
input- The input stringsecretKey- The AES secret key.iv- The Initialization Vector (IV) to augment the encryption.- Returns:
- The base64 encoded cipher text.
- Throws:
ApiException
-
AESEncrypt
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:
ApiExceptionNoApiKeyException
-
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:
ApiExceptionNoApiKeyException
-