Class DashScopeEncryptionUtils
java.lang.Object
io.agentscope.extensions.model.dashscope.DashScopeEncryptionUtils
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when encryption/decryption operations fail. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdecryptWithAes(SecretKey secretKey, byte[] iv, String encryptedData) Decrypt data using AES-GCM.static StringencryptAesKeyWithRsa(SecretKey aesSecretKey, String publicKeyBase64) Encrypt an AES secret key using RSA public key.static StringencryptWithAes(SecretKey secretKey, byte[] iv, String plaintext) Encrypt data using AES-GCM.static SecretKeyGenerate a new AES secret key for encryption.static byte[]Generate a unique initialization vector (IV) for AES-GCM encryption.
-
Method Details
-
generateAesSecretKey
Generate a new AES secret key for encryption.- Returns:
- a new AES-256 secret key
- Throws:
DashScopeEncryptionUtils.EncryptionException- if key generation fails
-
generateIv
public static byte[] generateIv()Generate a unique initialization vector (IV) for AES-GCM encryption.- Returns:
- a random 12-byte IV
-
encryptWithAes
Encrypt data using AES-GCM.- Parameters:
secretKey- the AES secret keyiv- the initialization vectorplaintext- the plaintext data to encrypt- Returns:
- Base64-encoded encrypted data
- Throws:
DashScopeEncryptionUtils.EncryptionException- if encryption fails
-
decryptWithAes
Decrypt data using AES-GCM.- Parameters:
secretKey- the AES secret keyiv- the initialization vectorencryptedData- Base64-encoded encrypted data- Returns:
- the decrypted plaintext
- Throws:
DashScopeEncryptionUtils.EncryptionException- if decryption fails
-
encryptAesKeyWithRsa
Encrypt an AES secret key using RSA public key.- Parameters:
aesSecretKey- the AES secret key to encryptpublicKeyBase64- Base64-encoded RSA public key- Returns:
- Base64-encoded encrypted AES key
- Throws:
DashScopeEncryptionUtils.EncryptionException- if encryption fails
-