AesCtrParams
Open source
AesCtrParams
The AesCtrParams
object represents the object that should be passed as the algorithm parameter into the
encrypt and
decrypt operation when using the AES-CTR algorithm.
For more details, head to the MDN Web Crypto API documentation on AES-CTR.
Properties
Property | Type | Description |
---|---|---|
name | string | Should be set to AES-CTR . |
counter | ArrayBuffer , TypedArray , or DataView | The initial value of the counter block. This must be 16-bytes long, like the AES block size. |
length | number | The number of bits in the counter block that are used for the actual counter. It is recommended to use 64 (half of the counter block). |
Example
JavaScript
export default async function () {
const plaintext = stringToArrayBuffer('Hello, World!');
/**
* Generate a symmetric key using the AES-CTR algorithm.
*/
const key = await crypto.subtle.generateKey(
{
name: 'AES-CTR',
length: 256,
},
true,
['encrypt', 'decrypt']
);
/**
* Encrypt the plaintext using the AES-CTR key with
* have generated.
*/
const ciphertext = await crypto.subtle.encrypt(
{
name: 'AES-CTR',
counter: crypto.getRandomValues(new Uint8Array(16)),
length: 128,
},
key,
plaintext
);
}
function stringToArrayBuffer(str) {
const buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
const bufView = new Uint16Array(buf);
for (let i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
24 Apr

Getting started with Grafana dashboard design
In this webinar, you'll learn how to design stylish and easily accessible Grafana dashboards that tell a story.
08 May

Grafana 12 deep dive
It wouldn’t be GrafanaCON without a new release. Join us as we dive into the latest features of Grafana 12, including dashboards as code, Git-based configs, dynamic dashboards, and more.
08 May

Monitoring EA App’s 200+ core error metrics with a scalable, color-coded Grafana dashboard
Learn how engineers at Electronic Arts built a Grafana dashboard that client teams can use to monitor 200+ core error metrics.