This library provides an easy to use interface for rsa en- and decryption.
Warning: This implementation has not been tested in production nor has it been examined by a security audit. All uses are your own responsibility.
To obtain a KeyPair
instance, one can call
KeyPair.parse(String pem, {String password})
. This parses
the given pem string and creates a KeyPair
instance with
all keys contained in this string.
KeyPair.encrypt
and KeyPair.decrypt
accept two input types:
String
Uint8List
.
The same applies for KeyPair.sign
and KeyPair.verify
.
If you want to encrypt and sign something, simply call KeyPair.publicEncrypt
.
This encrypts the given argument and signs the generated cipher. The output
is a PublicEncryptionResult
.
To decrypt and also verify the given PublicEncryptionResult
, call
KeyPair.privateDecrypt
. If the signature cannot be verified, this
throws an Error. otherwise, it returns the decrypted (if possible)
message.
All methods work as described in the
PKCS1 Standard, as default
they also apply the standard PKCS1-Padding.If you don't want to
use padding, simply set padding to null
. The default hash method
for EMSA_ENCODE is SHA256, currently only SHA256, MD5 and
SHA1 are implemented.
Help and pull requests are always appreciated!