AesCtrSecretKey class abstract

AES secret key for symmetric encryption and decryption using AES in Counter mode (CTR-mode), as described in NIST SP800-38A.

An AesCtrSecretKey can be imported from:

A random AesCtrSecretKey can be generated using AesCtrSecretKey.generateKey.

Example

import 'dart:convert' show utf8;
import 'dart:typed_data' show Uint8List;
import 'package:webcrypto/webcrypto.dart';

// Generate a new random AES-CTR secret key for AES-256.
final k = await AesCtrSecretKey.generate(256);

// Use a unique counter for each message.
final ctr = Uint8List(16); // always 16 bytes
fillRandomBytes(ctr);

// Length of the counter, the N'th right most bits of ctr are incremented
// for each block, the left most 128 - N bits are used as static nonce.
// Thus, messages must be less than 2^64 * 16 bytes.
final N = 64;

// Encrypt a message
final c = await k.encryptBytes(utf8.encode('hello world'), ctr, N);

// Decrypt message (requires the same counter ctr and length N)
print(utf8.decode(await k.decryptBytes(c, ctr, N))); // hello world
Annotations
  • @sealed

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decryptBytes(List<int> data, List<int> counter, int length) Future<Uint8List>
Decrypt data with this AesCtrSecretKey using AES in Counter mode, as specified in NIST SP800-38A.
decryptStream(Stream<List<int>> data, List<int> counter, int length) Stream<Uint8List>
Decrypt data with this AesCtrSecretKey using AES in Counter mode, as specified in NIST SP800-38A.
encryptBytes(List<int> data, List<int> counter, int length) Future<Uint8List>
Encrypt data with this AesCtrSecretKey using AES in Counter mode, as specified in NIST SP800-38A.
encryptStream(Stream<List<int>> data, List<int> counter, int length) Stream<Uint8List>
Encrypt data with this AesCtrSecretKey using AES in Counter mode, as specified in NIST SP800-38A.
exportJsonWebKey() Future<Map<String, dynamic>>
Export AesCtrSecretKey as JSON Web Key.
exportRawKey() Future<Uint8List>
Export AesCtrSecretKey as raw bytes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

generateKey(int length) Future<AesCtrSecretKey>
Generate random AesCtrSecretKey.
importJsonWebKey(Map<String, dynamic> jwk) Future<AesCtrSecretKey>
Import an AesCtrSecretKey from JSON Web Key.
importRawKey(List<int> keyData) Future<AesCtrSecretKey>
Import an AesCtrSecretKey from raw keyData.