Skip to content

qie.aesEncryptBytes

Signature: qie.aesEncryptBytes(inputBytes, key)

Returns: byte[] encryptedBytes - the encrypted bytes from the inputBytes

Encrypts inputBytes using AES encryption with the supplied key.

Note

This defaults to the ECB cipher algorithm mode and the PKCS5Padding cipher algorithm padding.

Parameters

Type Name Description Default
byte[] inputBytes the bytes to be encrypted
String or byte[] key the key to use for encryption

Example

// Prepare input bytes to encrypt
var messageBytes = new java.lang.String(
  "Top secret message: The secret lies with Charlotte."
).getBytes("utf-8");


// Example: key as byte[]
var aesKeyBytes = qie.base64DecodeToBytes(
  "jssPpyaaH5gCTII3mSV5qCsLuLmpfRWlOHT4mmZpYE4="
);

var encryptedBytes = qie.aesEncryptBytes(messageBytes, aesKeyBytes); // byte[]
var decryptedBytes = qie.aesDecryptBytes(encryptedBytes, aesKeyBytes);
var originalMessageDecoded = new java.lang.String(decryptedBytes, "utf-8");


// Example: key as String (must be 16, 24, or 32 bytes for AES)
var aesKeyString = "secret-key-12345"; // 16 bytes

var encryptedBytesWithStringKey = qie.aesEncryptBytes(messageBytes, aesKeyString); // byte[]
var decryptedBytesWithStringKey = qie.aesDecryptBytes(
  encryptedBytesWithStringKey,
  aesKeyString
);
var originalMessageWithStringKey = new java.lang.String(decryptedBytesWithStringKey, "utf-8");