dart_pg

Creator: coderz1093

Last updated:

Add to Cart

Description:

dart pg

Dart PG (Dart Privacy Guard) - The OpenPGP library in Dart language #
Dart PG is an implementation of the OpenPGP standard in Dart language.
It implements RFC4880, RFC5581, RFC6637,
parts of RFC4880bis.
Features #

Support data signing & encryption.
Support key management: key generation, key reading, key decryption.
Support public-key algorithms: RSA,
DSA,
ElGamal,
ECDSA,
EdDSA
and ECDH.
Support symmetric ciphers: 3DES, IDEA, CAST5, Blowfish, Twofish,
AES,
Camellia.
Support AEAD algorithms: EAX, OCB, GCM.
Support hash algorithms: MD5, SHA-1, RIPEMD-160, SHA-256, SHA-384, SHA-512, SHA-224.
Support compression algorithms: ZIP, ZLIB.
Support ECC curves:
secP256k1, secP384r1, secP521r1,
brainpoolP256r1, brainpoolP384r1, brainpoolP512r1,
curve25519, ed25519,
prime256v1.

Getting started #
In Dart or Flutter project add the dependency:
dependencies:
...
dart_pg:
copied to clipboard
Usage #
Encrypt and decrypt data with a password #
const text = 'Hello Dart PG!';
const password = 'secret stuff';

final encryptedMessage = await OpenPGP.encrypt(
OpenPGP.createTextMessage(text), passwords: [password]
);
final encrypted = encryptedMessage.armor();
final decryptedMessage = await OpenPGP.decrypt(
OpenPGP.readMessage(encrypted), passwords: [password]
);
final decrypted = decryptedMessage.armor();
copied to clipboard
Encrypt and decrypt data with PGP keys #
Encryption will use the algorithm preferred by the public (encryption) key (defaults to aes256 for keys generated),
and decryption will use the algorithm used for encryption.
const text = 'Hello Dart PG!';
const passphrase = 'secret stuff';
const armoredPublicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----';
const armoredPrivateKey = '-----BEGIN PGP PRIVATE KEY BLOCK-----';

final publicKey = await OpenPGP.readPublicKey(armoredPublicKey);
final privateKey = await OpenPGP.decryptPrivateKey(armoredPrivateKey, passphrase);

final encryptedMessage = await OpenPGP.encrypt(
OpenPGP.createTextMessage(text), encryptionKeys: [publicKey]
);
final encrypted = encryptedMessage.armor();

final decryptedMessage = await OpenPGP.decrypt(
OpenPGP.readMessage(encrypted), decryptionKeys: [privateKey]
);
final decrypted = decryptedMessage.armor();
copied to clipboard
Sign message & encrypt with multiple public keys:
final text = 'Hello Dart PG!';
const passphrase = 'secret stuff';
const armoredPublicKeys = ['-----BEGIN PGP PUBLIC KEY BLOCK-----'];
const armoredPrivateKey = '-----BEGIN PGP PRIVATE KEY BLOCK-----';

final publicKeys = await Future.wait(
armoredPublicKeys.map((armored) => OpenPGP.readPublicKey(armored))
);
final privateKey = await OpenPGP.decryptPrivateKey(armoredPrivateKey, passphrase);

final encryptedMessage = await OpenPGP.encrypt(
OpenPGP.createTextMessage(text),
encryptionKeys: publicKeys,
signingKeys: [privateKey],
);
final encrypted = encryptedMessage.armor();
copied to clipboard
Sign and verify cleartext #
const text = 'Hello Dart PG!';
const passphrase = 'secret stuff';
const armoredPublicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----';
const armoredPrivateKey = '-----BEGIN PGP PRIVATE KEY BLOCK-----';

final publicKey = await OpenPGP.readPublicKey(armoredPublicKey);
final privateKey = await OpenPGP.decryptPrivateKey(armoredPrivateKey, passphrase);

final signedMessage = await OpenPGP.sign(text, signingKeys: [privateKey]);
final signed = signedMessage.armor();

final verifiedMessage = await OpenPGP.verify(signed, verificationKeys: [publicKey]);
final verifications = verifiedMessage.verifications;
copied to clipboard
Detached sign and verify cleartext #
const text = 'Hello Dart PG!';
const passphrase = 'secret stuff';
const armoredPublicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----';
const armoredPrivateKey = '-----BEGIN PGP PRIVATE KEY BLOCK-----';

final publicKey = await OpenPGP.readPublicKey(armoredPublicKey);
final privateKey = await OpenPGP.decryptPrivateKey(armoredPrivateKey, passphrase);

final signature = await OpenPGP.signDetached(text, signingKeys: [privateKey]);
final armored = signature.armor();

final cleartextMessage = await OpenPGP.verifyDetached(
text, armored, verificationKeys: [publicKey]
);
final verifications = cleartextMessage.verifications;
copied to clipboard
Generate new key pair #
rsa type:
const passphrase = 'secret stuff';
final userID = [name, '($comment)', '<$email>'].join(' ');
final privateKey = await OpenPGP.generateKey(
[userID],
passphrase,
type: KeyGenerationType.rsa,
rsaKeySize: RSAKeySize.s4096,
);
final publicKey = privateKey.toPublic;
copied to clipboard
dsa type (uses DSA algorithm for signing & ElGamal algorithm for encryption):
const passphrase = 'secret stuff';
final userID = [name, '($comment)', '<$email>'].join(' ');
final privateKey = await OpenPGP.generateKey(
[userID],
passphrase,
type: KeyGenerationType.dsa,
dhKeySize: DHKeySize.l2048n224,
);
final publicKey = privateKey.toPublic;
copied to clipboard
ecdsa type (uses ECDSA algorithm for signing & ECDH algorithm for encryption): Possible values for curve are
secp256k1, secp384r1, secp521r1, brainpoolp256r1, brainpoolp384r1, brainpoolp512r1 and prime256v1
const passphrase = 'secret stuff';
final userID = [name, '($comment)', '<$email>'].join(' ');
final privateKey = await OpenPGP.generateKey(
[userID],
passphrase,
type: KeyGenerationType.ecdsa,
curve: CurveInfo.secp521r1,
);
final publicKey = privateKey.toPublic;
copied to clipboard
eddsa type (uses EdDSA algorithm with ed25519 for signing & ECDH algorithm with curve25519 for encryption):
const passphrase = 'secret stuff';
final userID = [name, '($comment)', '<$email>'].join(' ');
final privateKey = await OpenPGP.generateKey(
[userID],
passphrase,
type: KeyGenerationType.eddsa,
);
final publicKey = privateKey.toPublic;
copied to clipboard
Development #
To create your own build of the library, just run the following command after cloning the git repo.
This will download all dependencies, run the tests
dart pub get && dart test
copied to clipboard
Licensing #
BSD 3-Clause
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.