DashScopeEncryptionUtils
public final class DashScopeEncryptionUtils
io/agentscope/extensions/model/dashscope/DashScopeEncryptionUtils.java:42–181DashScope Encryption Utils,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 generateAesSecretKey、generateIv、encryptWithAes、decryptWithAes、encryptAesKeyWithRsa。
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
| 类Class | 类型Kind | 说明Description |
|---|---|---|
EncryptionException | 类class | Encryption 异常,表示执行过程中的错误。 Exception thrown when encryption/decryption operations fail. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static SecretKey generateAesSecretKey()static | 返回 `generateAesSecretKey` 结果。 Generate a new AES secret key for encryption. |
public static byte[] generateIv()static | 返回 `generateIv` 结果。 Generate a unique initialization vector (IV) for AES-GCM encryption. |
public static String encryptWithAes(SecretKey secretKey, byte[] iv, String plaintext)static | 执行 `encryptWithAes` 方法。 Encrypt data using AES-GCM. |
public static String decryptWithAes(SecretKey secretKey, byte[] iv, String encryptedData)static | 执行 `decryptWithAes` 方法。 Decrypt data using AES-GCM. |
public static String encryptAesKeyWithRsa(SecretKey aesSecretKey, String publicKeyBase64)static | 执行 `encryptAesKeyWithRsa` 方法。 Encrypt an AES secret key using RSA public key. |
方法详情Method Detail
generateAesSecretKey
public static SecretKey generateAesSecretKey()
返回 generateAesSecretKey 结果。
Generate a new AES secret key for encryption.
SecretKeyEncryptionException可能抛出 `EncryptionException`。if key generation fails
io/agentscope/extensions/model/dashscope/DashScopeEncryptionUtils.java:63–72generateIv
public static byte[] generateIv()
返回 generateIv 结果。
Generate a unique initialization vector (IV) for AES-GCM encryption.
byte[]io/agentscope/extensions/model/dashscope/DashScopeEncryptionUtils.java:79–84encryptWithAes
public static String encryptWithAes(SecretKey secretKey, byte[] iv, String plaintext)
执行 encryptWithAes 方法。
Encrypt data using AES-GCM.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
secretKey | SecretKey | AES 密钥密钥。the AES secret key |
iv | byte[] | iv(类型 `byte[]`)。the initialization vector |
plaintext | String | plaintext(类型 `String`)。the plaintext data to encrypt |
StringEncryptionException可能抛出 `EncryptionException`。if encryption fails
io/agentscope/extensions/model/dashscope/DashScopeEncryptionUtils.java:95–111decryptWithAes
public static String decryptWithAes(SecretKey secretKey, byte[] iv, String encryptedData)
执行 decryptWithAes 方法。
Decrypt data using AES-GCM.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
secretKey | SecretKey | AES 密钥密钥。the AES secret key |
iv | byte[] | iv(类型 `byte[]`)。the initialization vector |
encryptedData | String | 已加密数据(类型 `String`)。Base64-encoded encrypted data |
StringEncryptionException可能抛出 `EncryptionException`。if decryption fails
io/agentscope/extensions/model/dashscope/DashScopeEncryptionUtils.java:122–138encryptAesKeyWithRsa
public static String encryptAesKeyWithRsa(SecretKey aesSecretKey, String publicKeyBase64)
执行 encryptAesKeyWithRsa 方法。
Encrypt an AES secret key using RSA public key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
aesSecretKey | SecretKey | aes 密钥键(类型 `SecretKey`)。the AES secret key to encrypt |
publicKeyBase64 | String | public 键基类 64(类型 `String`)。Base64-encoded RSA public key |
StringEncryptionException可能抛出 `EncryptionException`。if encryption fails
io/agentscope/extensions/model/dashscope/DashScopeEncryptionUtils.java:148–167嵌套类详情Nested Class Detail
EncryptionException
public static class EncryptionException extends RuntimeExceptionEncryption 异常,表示执行过程中的错误。位于 io.agentscope.extensions.model.dashscope 包,继承自 RuntimeException。核心成员包括 EncryptionException。
Exception thrown when encryption/decryption operations fail.