decryptBytes abstract method
Decrypt data
encrypted with RsaOaepPublicKey.encryptBytes from the
matching public key.
If label
was specified when data
was encrypted, then the same label
must be specified during decryption. See RsaOaepPublicKey.encryptBytes
for more information about usages for label
.
Example
import 'dart:convert' show utf8;
import 'package:webcrypto/webcrypto.dart';
import 'package:pem/pem.dart';
// Generate a key-pair.
final keyPair = await RsaOaepPrivateKey.generateKey(
4096,
BigInt.from(65537),
Hash.sha256,
);
// Alice sends keyPair.publicKey to Bob
// Bob can generate a 256 bit symmetric secret key
final secretKeyToBeShared = await AesGcmSecretKey.generateKey(256);
// Using the public key Bob can encrypt secretKeyToBeShared, such that it
// can only be decrypted with the private key.
final encryptedRawKey = await keyPair.publicKey.encryptBytes(
await secretKeyToBeShared.exportRawKey(),
);
// Bob sends Alice: encryptedRawKey
// Given privateKey and encryptedRawKey Alice can decrypt the shared key.
final sharedRawSecretKey = await keypair.privateKey.decryptBytes(
encryptedRawKey,
);
final sharedSecretKey = await AesGcmSecretKey.importRaw(
sharedRawSecretKey,
);
// Now both Alice and Bob share a secret key.
Implementation
Future<Uint8List> decryptBytes(List<int> data, {List<int>? label});