AesCbcSecretKey class abstract

AES secret key for symmetric encryption and decryption using AES in Cipher Block Chaining mode (CBC-mode), as described in NIST SP800-38A.

Encrypted messages are always padded in PKCS#7 mode, as described in RFC 2315 Section 10.3 step 2. This padding is stripped when the message is decrypted.

An AesCbcSecretKey can be imported from:

A random AesCbcSecretKey can generated using AesCbcSecretKey.generateKey.

Example

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

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

// Use a unique IV for each message.
final iv = Uint8List(16);
fillRandomBytes(iv);

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

// Decrypt message (requires the same iv)
print(utf8.decode(await k.decryptBytes(c, iv))); // 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> iv) Future<Uint8List>
Decrypt data with this AesCbcSecretKey using AES in Cipher Block Chaining mode, as specified in NIST SP800-38A.
decryptStream(Stream<List<int>> data, List<int> iv) Stream<Uint8List>
Decrypt data with this AesCbcSecretKey using AES in Cipher Block Chaining mode, as specified in NIST SP800-38A.
encryptBytes(List<int> data, List<int> iv) Future<Uint8List>
Encrypt data with this AesCbcSecretKey using AES in Cipher Block Chaining mode, as specified in NIST SP800-38A.
encryptStream(Stream<List<int>> data, List<int> iv) Stream<Uint8List>
Encrypt data with this AesCbcSecretKey using AES in Cipher Block Chaining mode, as specified in NIST SP800-38A.
exportJsonWebKey() Future<Map<String, dynamic>>
Export AesCbcSecretKey as JSON Web Key.
exportRawKey() Future<Uint8List>
Export AesCbcSecretKey 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<AesCbcSecretKey>
Generate random AesCbcSecretKey.
importJsonWebKey(Map<String, dynamic> jwk) Future<AesCbcSecretKey>
Import an AesCbcSecretKey from JSON Web Key.
importRawKey(List<int> keyData) Future<AesCbcSecretKey>
Import an AesCbcSecretKey from raw keyData.