Skip to content

qie.aesDecryptBytes

Signature: qie.aesDecryptBytes(inputBytes, key)

Returns: byte[] decryptedBytes - the decrypted bytes from the inputBytes

Decrypts 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 decrypted
String or byte[] key the key to use for decrypting data

Example

// Prepare input bytes to encrypt/decrypt
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);
var decryptedBytes = qie.aesDecryptBytes(encryptedBytes, aesKeyBytes); // byte[]

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);
var decryptedBytesWithStringKey = qie.aesDecryptBytes(
   encryptedBytesWithStringKey,
   aesKeyString
); // byte[]

var originalMessageWithStringKey = new java.lang.String(decryptedBytesWithStringKey, "utf-8");