Class EncryptionUtils

java.lang.Object
com.alibaba.dashscope.transport.EncryptionUtils

public final class EncryptionUtils extends Object
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 Details

    • rsaEncrypt

      public static String rsaEncrypt(String input, String base64PublicKey)
      RSA-encrypt the input string; returns the base64 cipher text.
    • generateAesKey

      public static SecretKey generateAesKey()
      Generate a fresh AES-256 secret key.
    • generateIv

      public static byte[] generateIv()
      Random 96-bit GCM IV.
    • aesEncrypt

      public static String aesEncrypt(String input, SecretKey key, byte[] iv)
      AES-GCM encrypt; returns the base64 cipher text.
    • aesEncrypt

      public static String aesEncrypt(byte[] input, SecretKey key, byte[] iv)
      AES-GCM encrypt; returns the base64 cipher text.
    • aesDecrypt

      public static String aesDecrypt(String base64CipherText, SecretKey key, byte[] iv)
      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 string output, preserving request/error envelope fields.