AesGcmSecretKey class final
AES secret for symmetric encryption and decryption using AES in Galois/Counter Mode (GCM-mode), as described in NIST SP 800-38D.
An AesGcmSecretKey can be imported from:
- Raw bytes using AesGcmSecretKey.importRawKey, and,
- JWK format using AesGcmSecretKey.importJsonWebKey.
A random AesGcmSecretKey can be generated using AesGcmSecretKey.generateKey.
AES in GCM-mode is an authenticated encryption cipher, this means that that it includes checks that the ciphertext has not been modified.
Example
import 'dart:convert' show utf8;
import 'dart:typed_data' show Uint8List;
import 'package:webcrypto/webcrypto.dart';
// Generate a new random AES-GCM secret key for AES-256.
final k = await AesGcmSecretKey.generate(256);
// Use a unique IV for each message.
final iv = Uint8List(16);
fillRandomBytes(iv);
// Specify optional additionalData
final ad = utf8.encode('my-test-message');
// Encrypt a message
final c = await k.encryptBytes(
utf8.encode('hello world'),
iv,
additionalData: ad,
);
// Decrypt message (requires the same iv)
print(utf8.decode(await k.decryptBytes(
c,
iv,
additionalData: ad,
))); // hello world
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, {List<int> ? additionalData, int? tagLength = 128}) → Future<Uint8List> -
encryptBytes(
List< int> data, List<int> iv, {List<int> ? additionalData, int? tagLength = 128}) → Future<Uint8List> -
Encrypt
datawith this AesCbcSecretKey using AES in Galois/Counter Mode (GCM-mode), as specified in NIST SP 800-38D. -
exportJsonWebKey(
) → Future< Map< String, dynamic> > - Export AesGcmSecretKey as JSON Web Key.
-
exportRawKey(
) → Future< Uint8List> - Export AesGcmSecretKey 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< AesGcmSecretKey> - Generate a random AesGcmSecretKey.
-
importJsonWebKey(
Map< String, dynamic> jwk) → Future<AesGcmSecretKey> - Import an AesGcmSecretKey from JSON Web Key.
-
importRawKey(
List< int> keyData) → Future<AesGcmSecretKey> -
Import an AesGcmSecretKey from raw
keyData.