This project is being relicensed from a combination of the "GNU LESSER GENERAL PUBLIC LICENSE 3.0" and "Mozilla Public License 2.0" to the Bouncy Castle license. The new license can be read in the LICENSE file.
Subsequent to this change, this library will be transitioned into the Bouncy Castle project. The Bouncy Castle team will take over the maintenance and development of this library.
See https://github.com/bcgit/pc-dart for the new code.
A Dart library for encryption and decryption. In this release, most of the classes are ports of Bouncy Castle from Java to Dart. The porting is almost always direct except for some classes that had been added to ease the use of low level data.
To make sure nothing fails, tests and benchmarks for every algorithm are provided. The expected results are taken from the Bouncy Castle Java version and also from standards, and matched against the results got from Pointy Castle.
In this release, the following algorithms are implemented:
Block ciphers:
Asymmetric block ciphers:
Asymmetric block cipher encodings:
Stream ciphers:
Block cipher modes of operation:
Paddings:
Digests:
*Keccak is currently implemented as SHA3Digest.
MACs:
Signatures:
Password based key derivators:
Asymmetric key generators:
Secure PRNGs:
There are two ways to instantiate objects that implement the algorithms:
Using the registry, the algorithm name is provided to high-level class factories.
This is especially convenient when an algorithm involves multiple algorithm implementation classes to implement. All the necessary classes can all be instantiated with a single name (e.g. "HMAC/SHA-256" or "SHA-1/HMAC/PBKDF2"), and they are automatically combined together with the correct values.
To use the registry, either import pointycastle.dart
or
export.dart
. For example,
import "package:pointycastle/pointycastle.dart";
final sha256 = Digest("SHA-256");
final sha1 = Digest("SHA-1");
final md5 = Digest("MD5");
final hmacSha256 = Mac("SHA-256/HMAC");
final hmacSha1 = Mac("SHA-1/HMAC");
final hmacMd5 = Mac("MD5/HMAC");
final derivator = KeyDerivator("SHA-1/HMAC/PBKDF2");
final signer = Signer("SHA-256/RSA");
Without the registry, each implementation class must be instantiated using its constructor.
If an algorithm involves multiple algorithm implementation classes, they each have to be individually instantiated and combined together with the correct values.
To use the constructors, import export.dart
. For example,
import "package:pointycastle/export.dart";
final sha256 = SHA256Digest();
final sha1 = SHA1Digest();
final md5 = MD5Digest();
final hmacSha256 = HMac(SHA256Digest(), 64);
final hmacSha512 = HMac(SHA512Digest(), 128);
final hmacMd5 = HMac(MD5Digest(), 64);
final derivator = PBKDF2KeyDerivator(HMac(SHA256Digest(), 64));
final signer = RSASigner(SHA256Digest(), '0609608648016503040201');
Using the registry means that all algorithms will be imported by default, which can increase the compiled size of your program.
To avoid this, instantiate all classes directly by using their constructors.
There are two main approaches for importing Point Castle libraries:
It is also possible to import api.dart (the high-level API) and selectively import individual implementation classes as they are needed. But this method requires a lot more programmer effort, and no longer has any advantage over simply importing export.dart and relying Dart's tree shaking to leave out code that is not needed.
The registry can be used with any of these approaches. The different approaches only affects access to the implementation classes.
Therefore, when avoiding the code size overheads of the registry, be careful not to accidentally use the registry. Since the single use of a factory from the registry will cause the entire registry to be loaded.
Some articles on how to use some of Pointy Castle's features can be found under the tutorials directory in the sources.
Note: the above links are to the most recent versions on the master branch on GitHub. They may be different from the version here.