RsaOaepPrivateKey class abstract
RSAES-OAEP private key for decryption of messages.
An RsaOaepPrivateKey instance holds a private RSA key for decrypting messages using the RSAES-OAEP scheme as specified in RFC 3447.
An RsaOaepPrivateKey can be imported from:
- PKCS #8 format using RsaOaepPrivateKey.importPkcs8Key, and,
- JWK format using RsaOaepPrivateKey.importJsonWebKey.
A public-private KeyPair consisting of a RsaOaepPublicKey and a RsaOaepPrivateKey can be generated using RsaOaepPrivateKey.generateKey.
Example
import 'dart:typed_data' show Uint8List;
import 'dart:convert' show utf8;
import 'package:webcrypto/webcrypto.dart';
// Generate a public / private key-pair.
final keyPair = await RsaOaepPrivateKey.generateKey(
4096,
BigInt.from(65537),
Hash.sha256,
);
// Generate a 256 bit symmetric key
final secretKeyToBeShared = await AesGcmSecretKey.generateKey(256);
// Using publicKey Bob can encrypt secretKeyToBeShared, such that it can
// only be decrypted with the private key.
final encryptedRawKey = await keyPair.publicKey.encryptBytes(
await secretKeyToBeShared.exportRawKey(),
label: 'shared-key',
);
// Given privateKey and encryptedRawKey Alice can decrypt the shared key.
final sharedRawSecretKey = await keypair.privateKey.decryptBytes(
encryptedRawKey,
label: 'shared-key',
);
final sharedSecretKey = await AesGcmSecretKey.importRaw(sharedRawSecretKey);
// Now both Alice and Bob share a secret key.
The size of the message to be encrypted is limited to
message.length <= (modulusLength - 2 * hashLength - 2) / 8
.
Thus, RsaOaepPublicKey.encryptBytes is usually only used to encrypt the
key for symmetric cipher like AesCbcSecretKey, AesCtrSecretKey or
AesGcmSecretKey, after which the symmetric cipher can be used
encrypt/decrypt larger messages.
- 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> ? label}) → Future<Uint8List> -
Decrypt
data
encrypted with RsaOaepPublicKey.encryptBytes from the matching public key. -
exportJsonWebKey(
) → Future< Map< String, dynamic> > - Export RSAES-OAEP private key in JSON Web Key format.
-
exportPkcs8Key(
) → Future< Uint8List> - Export this RSAES-OAEP private key in PKCS #8 format.
-
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 modulusLength, BigInt publicExponent, Hash hash) → Future< KeyPair< RsaOaepPrivateKey, RsaOaepPublicKey> > - Generate an RSAES-OAEP public/private key-pair.
-
importJsonWebKey(
Map< String, dynamic> jwk, Hash hash) → Future<RsaOaepPrivateKey> - Import RSAES-OAEP private key in JSON Web Key format.
-
importPkcs8Key(
List< int> keyData, Hash hash) → Future<RsaOaepPrivateKey> - Import RSAES-OAEP private key in PKCS #8 format.