Updated on 2024-03-05 GMT+08:00

AesUtils

Path

com.roma.apic.livedata.common.v1.AesUtils

Description

This class is used to provide the AES encryption and decryption methods.

Example

Encryption:

importClass(com.roma.apic.livedata.common.v1.AesUtils);
function execute(data) {
  var plainText = "plainText";
//Hard-coded encryption and decryption keys pose higher security risks. You are advised to store the key in the configuration file. This example uses the secretKey configured for the custom backend.
  var secretKey = "#{secretKey}";
  var initialVector = "initialVector";
  var encryptText = AesUtils.encrypt(plainText, secretKey, initialVector, AesUtils.KEYLENGTH.KL_128, AesUtils.MODE.GCM, AesUtils.PAD.NOPADDING);
  return encryptText
}

Decryption:

importClass(com.roma.apic.livedata.common.v1.AesUtils);
function execute(data) {
  var encryptText = "encryptText";
//Hard-coded encryption and decryption keys pose higher security risks. You are advised to store the key in the configuration file. This example uses the secretKey configured for the custom backend.
  var secretKey = "#{secretKey}";
  var initialVector = "initialVector";
  var decryptText = AesUtils.decrypt(encryptText, secretKey, initialVector, AesUtils.KEYLENGTH.KL_128, AesUtils.MODE.GCM, AesUtils.PAD.NOPADDING);
  return decryptText
}

Method List

Returned Type

Method and Description

static java.lang.String

decrypt(java.lang.String encryptText, java.lang.String secretKey)

Decrypt the ciphertext using the AES algorithm and a private key.

static java.lang.String

encrypt(java.lang.String plainText, java.lang.String secretKey)

Encrypt the plaintext using the AES algorithm and a private key.

static java.lang.String

decrypt(java.lang.String encryptText, java.lang.String secretKey, java.lang.String initialVector, AesUtils.KEYLENGTH length, AesUtils.MODE mode, AesUtils.PAD pad)

Decrypt the ciphertext using the AES algorithm and a private key with specified mode and length.

static java.lang.String

encrypt(java.lang.String plainText, java.lang.String secretKey, java.lang.String initialVector, AesUtils.KEYLENGTH length, AesUtils.MODE mode, AesUtils.PAD pad)

Encrypt the plaintext using the AES algorithm and a private key with specified mode and length.

Method Details

  • public static java.lang.String decrypt(java.lang.String encryptText, java.lang.String secretKey)

    Decrypting ciphertext using the AES algorithm and a private key

    Input Parameters

    • encryptText: ciphertext to be decrypted (a maximum of 8192 characters).
    • secretKey: secret key.

    Returns

    Decrypted data

  • public static java.lang.String encrypt(java.lang.String plainText, java.lang.String secretKey)

    Encrypting plaintext using the AES algorithm and a private key

    Input Parameters

    • plainText: plaintext to be encrypted (a maximum of 4096 characters).
    • secretKey: secret key.

    Returns

    Encrypted data

  • public static java.lang.String decrypt(java.lang.String encryptText, java.lang.String secretKey, java.lang.String initialVector, AesUtils.KEYLENGTH length, AesUtils.MODE mode, AesUtils.PAD pad)

    Decrypting ciphertext using the AES algorithm and a private key with mode and length specified.

    Input Parameters

    • encryptText: ciphertext to be decrypted (a maximum of 8192 characters).
    • secretKey: secret key.
    • initialVector: initial vector.
    • length: length of the key. The options are AesUtils.KEYLENGTH.KL_0, AesUtils.KEYLENGTH.KL_128, AesUtils.KEYLENGTH.KL_192, and AesUtils.KEYLENGTH.KL_256.
    • mode: working mode. The options are AesUtils.MODE.GCM and AesUtils.MODE.CTR.
    • pad: padding mode. The options are AesUtils.PAD.PKCS5PADDING and AesUtils.PAD.NOPADDING.

    Returns

    Decrypted data

  • public static java.lang.String encrypt(java.lang.String plainText, java.lang.String secretKey, java.lang.String initialVector, AesUtils.KEYLENGTH length, AesUtils.MODE mode, AesUtils.PAD pad)

    Encrypting plaintext using the AES algorithm and a private key with specified mode and length.

    Input Parameters

    • plainText: plaintext to be encrypted (a maximum of 4096 characters).
    • secretKey: secret key.
    • initialVector: initial vector.
    • length: length of the key. The options are AesUtils.KEYLENGTH.KL_0, AesUtils.KEYLENGTH.KL_128, AesUtils.KEYLENGTH.KL_192, and AesUtils.KEYLENGTH.KL_256.
    • mode: working mode. The options are AesUtils.MODE.GCM and AesUtils.MODE.CTR.
    • pad: padding mode. The options are AesUtils.PAD.PKCS5PADDING and AesUtils.PAD.NOPADDING.

    Returns

    Encrypted data