Package com.alibaba.dashscope.transport
Class EncryptionUtils
java.lang.Object
com.alibaba.dashscope.transport.EncryptionUtils
Crypto primitives for the encrypted channel (J7, ported from 2.x utils/EncryptionUtils):
RSA-wrapped AES-256-GCM. Wire shape: the request carries an
X-DashScope-EncryptionKey
JSON header (public_key_id/encrypt_key/iv) and the sensitive body part is AES-GCM
encrypted.
Failure model: a JDK that lacks RSA/AES-GCM is a broken environment → IllegalStateException; malformed caller input (bad key/iv/ciphertext) → IllegalArgumentException.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringaesDecrypt(String base64CipherText, SecretKey key, byte[] iv) AES-GCM decrypt a base64 cipher text.static StringaesEncrypt(byte[] input, SecretKey key, byte[] iv) AES-GCM encrypt; returns the base64 cipher text.static StringaesEncrypt(String input, SecretKey key, byte[] iv) AES-GCM encrypt; returns the base64 cipher text.static com.fasterxml.jackson.databind.JsonNodedecryptOutput(com.fasterxml.jackson.databind.JsonNode body, EncryptionConfig config) Decrypt a top-level stringoutput, preserving request/error envelope fields.static SecretKeyGenerate a fresh AES-256 secret key.static byte[]Random 96-bit GCM IV.static StringrsaEncrypt(String input, String base64PublicKey) RSA-encrypt the input string; returns the base64 cipher text.
-
Method Details
-
rsaEncrypt
RSA-encrypt the input string; returns the base64 cipher text. -
generateAesKey
Generate a fresh AES-256 secret key. -
generateIv
public static byte[] generateIv()Random 96-bit GCM IV. -
aesEncrypt
AES-GCM encrypt; returns the base64 cipher text. -
aesEncrypt
AES-GCM encrypt; returns the base64 cipher text. -
aesDecrypt
AES-GCM decrypt a base64 cipher text. -
decryptOutput
public static com.fasterxml.jackson.databind.JsonNode decryptOutput(com.fasterxml.jackson.databind.JsonNode body, EncryptionConfig config) Decrypt a top-level stringoutput, preserving request/error envelope fields.
-