pointycastle 1.0.2

  • Readme
  • Changelog
  • Installing
  • 63

!!! Important Message !!!

The only maintainer of this library, @stevenroose, is no longer able to actively maintain this library. If anyone would be willing to take over maintainership, I would be glad to discuss that. (Don't worry I won't give pub push access to anyone without having enough confidence in their good intentions.) Until then, please only make issues for real bugs instead of feature requests. PRs are still welcome, but I can't guarantee that I will have the time to review them.

Pointy Castle #

A Dart library for encryption and decryption. As of today, 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.

Algorithms #

As of the last release, the following algorithms are implemented:

Block ciphers:

  • AES

Asymmetric block ciphers:

  • RSA

Asymmetric block cipher encodings:

  • PKCS1
  • OAEP

Stream ciphers:

  • Salsa20

Block cipher modes of operation:

  • CBC (Cipher Block Chaining mode)
  • CFB (Cipher Feedback mode)
  • ECB (Electronic Code Book mode)
  • GCTR (GOST 28147 OFB counter mode)
  • OFB (Output FeedBack mode)
  • CTR (Counter mode)
  • SIC

Paddings:

  • PKCS7
  • ISO7816-4

Digests:

  • Blake2b
  • MD2
  • MD4
  • MD5
  • RIPEMD-128|160|256|320
  • SHA-1
  • SHA-224|256|384|512
  • SHA-512/t (t=8 to 376 and 392 to 504 in multiples of 8)
  • Keccak-224|256|384|512*
  • Tiger
  • Whirlpool

*Keccak is currently implemented as SHA3Digest.

MACs:

  • HMAC
  • CMAC

Signatures:

  • (DET-)ECDSA
  • RSA

Password based key derivators:

  • PBKDF2
  • scrypt

Asymmetric key generators:

  • ECDSA
  • RSA

Secure PRNGs:

  • Based on block cipher in CTR mode
  • Based on block cipher in CTR mode with auto reseed (for forward security)
  • Based on Fortuna algorithm

Usage #

There are two ways to use the algorithms that PointyCastle provides: with or without using the registry.

Registry #

The registry allows users to easily instantiate classes for the algorithms using the algorithm shorthands like given in the list above. It also makes it possible to seamlessly chain different algorithms together. For example:

import "package:pointycastle/pointycastle.dart";

void main() {
  Digest sha256 = new Digest("SHA-256");
  // or
  KeyDerivator derivator = new KeyDerivator("SHA-1/HMAC/PBKDF2");
}

Without the registry #

Using the registry means that all algorithms will be imported by default, which can possibly increase the compiled size of your program. To avoid this, it is possible to import algorithms one by one. In that case, you can decide to either use the classes directly, or still use the registry. But remember that the registry only contains the classes that you import. For example:

import "package:pointycastle/api.dart";

import "package:pointycastle/digests/sha256.dart";

import "package:pointycastle/digests/sha1.dart";
import "package:pointycastle/macs/hmac.dart";
import "package:pointycastle/key_derivators/pbkdf2.dart";

void main() {
  Digest sha256 = new SHA256Digest();
  // or
  KeyDerivator derivator = new PBKDF2KeyDerivator(
      new HMac(new SHA1Digest(), 64));

  // But the registry keeps working for all imported algorithms:

  Digest sha256 = new Digest("SHA-256");
  // or
  KeyDerivator derivator = new KeyDerivator("SHA-1/HMAC/PBKDF2");
}

Libraries #

  • package:pointycastle/pointycastle.dart: exports the high-level API and the registry loaded with all available implementations
  • package:pointycastle/api.dart: exports the high-level API and the registry without any implementations
  • package:pointycastle/export.dart: exports the API and all implementation classes

Changelog #

Version 1.0.2 (2019-11-15) #

  • Add non-Keccak SHA3 support
  • Add CMAC support ("AES/CMAC")
  • Add ISO7816-4 padding support
  • Fixes in CBCBlockCipherMac and CMac

Version 1.0.1 (2019-02-20) #

  • Add Blake2b support

Version 1.0.0 (2018-12-17) (Dart SDK version 2.0) #

  • Support Dart 2 and Strong Mode
  • Migrate from package:bignum.BigInteger to dart:core.BigInt
  • Remove Quiver and fixnum dependency
  • OAEP encoding for block ciphers

Version 0.10.0 (2016-02-04) (Dart SDK version 0.14.0) #

  • First Pointy Castle release.

  • Reorganised file structure.

  • Completely new Registry implementation that dynamically loads imported implementations using reflection. It is explained in this commit.

  • Migrated from unittest to test package.

cipher releases #

Version 0.8.0 (2014-??-??) (Dart SDK version ???) #

  • [bug 80] PaddedBlockCipher doesn't add padding when data length is a multiple of the block size. This fix introduces a BREAKING CHANGE in PaddedBlockCipher specification. Read its API documentation to know about the changes.

Version 0.7.0 (2014-03-22) (Dart SDK version 1.3.0-dev.5.2) #

  • [enh 15] Implement stream cipher benchmarks.

  • [enh 64] Benchmark and optimize digests.

  • [enh 74] Make SHA-3 usable in terms of speed.

  • [bug 67] Removed some unused code.

  • [bug 68] Fix process() method of PaddedBlockCipher.

  • [bug 75] Remove a registry dependency in the Scrypt algorithm.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pointycastle: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pointycastle/pointycastle.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
94
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
82
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:pointycastle/pointycastle.dart.

Health suggestions

Fix lib/digests/tiger.dart. (-99.47 points)

Analysis of lib/digests/tiger.dart reported 1044 hints, including:

line 17 col 7: Unnecessary new keyword.

line 20 col 30: Unnecessary new keyword.

line 21 col 30: Unnecessary new keyword.

line 23 col 14: Unnecessary new keyword.

line 24 col 14: Unnecessary new keyword.

Fix lib/src/impl/long_sha2_family_digest.dart. (-45.75 points)

Analysis of lib/src/impl/long_sha2_family_digest.dart reported 122 hints, including:

line 16 col 35: Unnecessary new keyword.

line 18 col 14: Unnecessary new keyword.

line 19 col 14: Unnecessary new keyword.

line 20 col 14: Unnecessary new keyword.

line 21 col 14: Unnecessary new keyword.

Fix lib/key_generators/rsa_key_generator.dart. (-44.65 points)

Analysis of lib/key_generators/rsa_key_generator.dart reported 118 hints, including:

line 18 col 7: Unnecessary new keyword.

line 31 col 17: Unnecessary new keyword.

line 36 col 13: Unnecessary new keyword.

line 40 col 13: Unnecessary new keyword.

line 122 col 12: Unnecessary new keyword.

Fix additional 119 files with analysis or formatting issues. (-342.33 points)

Additional issues in the following files:

  • lib/ecc/ecc_fp.dart (46 hints)
  • lib/digests/blake2b.dart (32 hints)
  • lib/signers/ecdsa_signer.dart (31 hints)
  • lib/digests/sha3.dart (27 hints)
  • lib/src/ufixnum.dart (24 hints)
  • lib/digests/whirlpool.dart (21 hints)
  • lib/macs/cmac.dart (20 hints)
  • lib/key_derivators/scrypt.dart (18 hints)
  • lib/asymmetric/pkcs1.dart (17 hints)
  • lib/digests/sha512t.dart (17 hints)
  • lib/macs/cbc_block_cipher_mac.dart (17 hints)
  • lib/block/modes/cfb.dart (15 hints)
  • lib/signers/rsa_signer.dart (15 hints)
  • lib/asymmetric/oaep.dart (14 hints)
  • lib/ecc/ecc_base.dart (13 hints)
  • lib/stream/salsa20.dart (12 hints)
  • lib/block/aes_fast.dart (11 hints)
  • lib/block/modes/gctr.dart (10 hints)
  • lib/block/modes/ofb.dart (10 hints)
  • lib/block/modes/cbc.dart (9 hints)
  • lib/key_derivators/pbkdf2.dart (9 hints)
  • lib/random/auto_seed_block_ctr_random.dart (8 hints)
  • lib/stream/sic.dart (8 hints)
  • lib/macs/hmac.dart (7 hints)
  • lib/padded_block_cipher/padded_block_cipher_impl.dart (7 hints)
  • lib/random/fortuna_random.dart (7 hints)
  • lib/src/impl/md4_family_digest.dart (7 hints)
  • lib/asymmetric/rsa.dart (6 hints)
  • lib/random/block_ctr_random.dart (6 hints)
  • lib/block/modes/sic.dart (5 hints)
  • lib/digests/md2.dart (5 hints)
  • lib/key_generators/ec_key_generator.dart (5 hints)
  • lib/block/modes/ctr.dart (4 hints)
  • lib/ecc/curves/brainpoolp160r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp160t1.dart (4 hints)
  • lib/ecc/curves/brainpoolp192r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp192t1.dart (4 hints)
  • lib/ecc/curves/brainpoolp224r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp224t1.dart (4 hints)
  • lib/ecc/curves/brainpoolp256r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp256t1.dart (4 hints)
  • lib/ecc/curves/brainpoolp320r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp320t1.dart (4 hints)
  • lib/ecc/curves/brainpoolp384r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp384t1.dart (4 hints)
  • lib/ecc/curves/brainpoolp512r1.dart (4 hints)
  • lib/ecc/curves/brainpoolp512t1.dart (4 hints)
  • lib/ecc/curves/gostr3410_2001_cryptopro_a.dart (4 hints)
  • lib/ecc/curves/gostr3410_2001_cryptopro_b.dart (4 hints)
  • lib/ecc/curves/gostr3410_2001_cryptopro_c.dart (4 hints)
  • lib/ecc/curves/gostr3410_2001_cryptopro_xcha.dart (4 hints)
  • lib/ecc/curves/gostr3410_2001_cryptopro_xchb.dart (4 hints)
  • lib/ecc/curves/prime192v1.dart (4 hints)
  • lib/ecc/curves/prime192v2.dart (4 hints)
  • lib/ecc/curves/prime192v3.dart (4 hints)
  • lib/ecc/curves/prime239v1.dart (4 hints)
  • lib/ecc/curves/prime239v2.dart (4 hints)
  • lib/ecc/curves/prime239v3.dart (4 hints)
  • lib/ecc/curves/prime256v1.dart (4 hints)
  • lib/ecc/curves/secp112r1.dart (4 hints)
  • lib/ecc/curves/secp112r2.dart (4 hints)
  • lib/ecc/curves/secp128r1.dart (4 hints)
  • lib/ecc/curves/secp128r2.dart (4 hints)
  • lib/ecc/curves/secp160k1.dart (4 hints)
  • lib/ecc/curves/secp160r1.dart (4 hints)
  • lib/ecc/curves/secp160r2.dart (4 hints)
  • lib/ecc/curves/secp192k1.dart (4 hints)
  • lib/ecc/curves/secp192r1.dart (4 hints)
  • lib/ecc/curves/secp224k1.dart (4 hints)
  • lib/ecc/curves/secp224r1.dart (4 hints)
  • lib/ecc/curves/secp256k1.dart (4 hints)
  • lib/ecc/curves/secp256r1.dart (4 hints)
  • lib/ecc/curves/secp384r1.dart (4 hints)
  • lib/ecc/curves/secp521r1.dart (4 hints)
  • lib/src/impl/secure_random_base.dart (4 hints)
  • lib/src/registry/registry.dart (4 hints)
  • lib/src/utils.dart (4 hints)
  • lib/block/modes/ecb.dart (3 hints)
  • lib/paddings/pkcs7.dart (3 hints)
  • lib/src/api/block_cipher.dart (3 hints)
  • lib/src/api/mac.dart (3 hints)
  • lib/src/api/padded_block_cipher.dart (3 hints)
  • lib/src/impl/base_padding.dart (3 hints)
  • lib/stream/ctr.dart (3 hints)
  • lib/digests/sha224.dart (2 hints)
  • lib/digests/sha256.dart (2 hints)
  • lib/digests/sha384.dart (2 hints)
  • lib/digests/sha512.dart (2 hints)
  • lib/impl.dart (2 hints)
  • lib/paddings/iso7816d4.dart (2 hints)
  • lib/src/api/asymmetric_block_cipher.dart (2 hints)
  • lib/src/api/digest.dart (2 hints)
  • lib/src/api/key_derivator.dart (2 hints)
  • lib/src/api/key_generator.dart (2 hints)
  • lib/src/api/padding.dart (2 hints)
  • lib/src/api/stream_cipher.dart (2 hints)
  • lib/api.dart (1 hint)
  • lib/digests/md4.dart (1 hint)
  • lib/digests/md5.dart (1 hint)
  • lib/digests/ripemd128.dart (1 hint)
  • lib/digests/ripemd160.dart (1 hint)
  • lib/digests/ripemd256.dart (1 hint)
  • lib/digests/ripemd320.dart (1 hint)
  • lib/digests/sha1.dart (1 hint)
  • lib/ecc/api.dart (1 hint)
  • lib/export.dart (1 hint)
  • lib/pointycastle.dart (1 hint)
  • lib/src/api/padded_block_cipher_parameters.dart (1 hint)
  • lib/src/api/parameters_with_iv.dart (1 hint)
  • lib/src/api/parameters_with_random.dart (1 hint)
  • lib/src/api/secure_random.dart (1 hint)
  • lib/src/api/signer.dart (1 hint)
  • lib/src/ec_standard_curve_constructor.dart (1 hint)
  • lib/src/impl/base_asymmetric_block_cipher.dart (1 hint)
  • lib/src/impl/base_block_cipher.dart (1 hint)
  • lib/src/impl/base_digest.dart (1 hint)
  • lib/src/impl/base_key_derivator.dart (1 hint)
  • lib/src/impl/base_mac.dart (1 hint)
  • lib/src/impl/base_stream_cipher.dart (1 hint)

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and pointycastle.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=0.8.10+6 <3.0.0
Dev dependencies
benchmark_harness >=1.0.5 <2.0.0
matcher >=0.12.0 <0.13.0
test >=0.12.30 <1.4.0