Decrypts the provided data using AES-CTR.
The parameters for the decryption operation.
A Promise that resolves to the decrypted data as a Uint8Array.
This method performs AES-CTR decryption on the given encrypted data using the specified key. Similar to the encryption process, it requires an initial counter block and the length of the counter block, along with the encrypted data and the decryption key. The method returns the decrypted data as a Uint8Array.
const aesCtr = new AesCtrAlgorithm();
const encryptedData = new Uint8Array([...]); // Encrypted data
const counter = new Uint8Array(16); // 16-byte (128-bit) counter block used during encryption
const key = { ... }; // A Jwk object representing the same AES key used for encryption
const decryptedData = await aesCtr.decrypt({
data: encryptedData,
counter,
key,
length: 128 // Length of the counter in bits
});
Encrypts the provided data using AES-CTR.
The parameters for the encryption operation.
A Promise that resolves to the encrypted data as a Uint8Array.
This method performs AES-CTR encryption on the given data using the specified key. It requires the initial counter block and the length of the counter block, alongside the data and key. The method is designed to work asynchronously and returns the encrypted data as a Uint8Array.
const aesCtr = new AesCtrAlgorithm();
const data = new TextEncoder().encode('Messsage');
const counter = new Uint8Array(16); // 16-byte (128-bit) counter block
const key = { ... }; // A Jwk object representing an AES key
const encryptedData = await aesCtr.encrypt({
data,
counter,
key,
length: 128 // Length of the counter in bits
});
Generates a symmetric key for AES in Counter (CTR) mode in JSON Web Key (JWK) format.
The parameters for the key generation.
A Promise that resolves to the generated symmetric key in JWK format.
This method generates a symmetric AES key for use in CTR mode, based on the specified
algorithm
parameter which determines the key length. It uses cryptographically secure random
number generation to ensure the uniqueness and security of the key. The key is returned in JWK
format.
The generated key includes the following components:
kty
: Key Type, set to 'oct' for Octet Sequence.k
: The symmetric key component, base64url-encoded.kid
: Key ID, generated based on the JWK thumbprint.const aesCtr = new AesCtrAlgorithm();
const privateKey = await aesCtr.generateKey({ algorithm: 'A256CTR' });
The
AesCtrAlgorithm
class provides a concrete implementation for cryptographic operations using the AES algorithm in Counter (CTR) mode. This class implements bothCipher
andKeyGenerator
interfaces, providing key generation, encryption, and decryption features.This class is typically accessed through implementations that extend the
CryptoApi
interface.