Giter VIP home page Giter VIP logo

pointycastle's Introduction

!!! Important Message !!!

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.

Pointy Castle

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.

Algorithms

In this 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

Instantiating implementation objects

There are two ways to instantiate objects that implement the algorithms:

  • using the registry, or
  • without the registry.

Using the registry

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

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');

Registry vs without registry

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.

Importing libraries

There are two main approaches for importing Point Castle libraries:

  • only import pointycastle.dart (which includes the high-level API and the interfaces); or
  • only import export.dart (which includes the high-level API, interfaces and all the implementation classes).

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.

Tutorials

Some articles on how to use some of Pointy Castle's features can be found under the tutorials directory in the sources.

  • Calculating a digest - calculating a hash or digest (e.g. SHA-256, SHA-1, MD5)
  • Calculating a HMAC - calculating a hash-based message authentication code (e.g. HMAC-SHA256, HMAC-SHA1)
  • Using AES-CBC - block encryption and decryption with AES-CBC
  • Using RSA - key generation, signing/verifying, and encryption/decryption
  • Some tips on using Pointy Castle

Note: the above links are to the most recent versions on the master branch on GitHub. They may be different from the version here.

pointycastle's People

Contributors

azenla avatar bbedward avatar duncanhoggan avatar greenappers avatar hoylen avatar ivan-zaera avatar izaera avatar jadengis avatar jminer avatar johnpryan avatar mraleph avatar paulreimer avatar proteye avatar sethladd avatar stevenroose avatar yshrsmz avatar zewebdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pointycastle's Issues

Adapt to Dart 1.0 release

From @izaera on November 12, 2013 7:33

Now is the time to get your package ready for Dart's release.

If you author Dart packages hosted on pub.dartlang.org, please read on for this important call for participation.

Hello Dart package authors! Time to test and stabilize your packages, and get ready for Dart 1.0. Wait, what?! 1.0? Forealz? Not yet, but soon. You can help the community, and new users, have a successful 1.0 launch by following these steps:

  1. Please update your Dart Editor and SDK to 0.8.10+8 or later.

  2. Update your library's pubspec.yaml with specific version constraints. Please add:

environment:

sdk: ">=0.8.10+6 <2.0.0"

If your package depends on packages produced by the Dart team, like "args", "unittest", "polymer", etc, please use these specific lower and upper bounds:

analyzer: >=0.10.1 < 0.11.0

everything else: >=0.9.0 < 0.10.0

These specific versions protect your package, and more importantly your users, in the face of potential breaking changes in dependencies. Sometime after the 1.0 launch, each package will get its own release cadence.

That's right, the days of 'any' for library packages are over. With a stable SDK, there's no reason to force your users to live on the bleeding edge. Let's all stabilize the Dart community by specifying version dependencies for our libraries.

  1. Test your package, and fix any breaks.

  2. Bump the version of your package.

If your package is >=1.0: Add +1.0.0 if you introduced a breaking change, add +0.1.0 if you added a feature (and it does not break existing users), or add +0.0.1 if it is a bugfix.

if your package is <1.0: technically anything less than 1.0 can break at any time. However we have found the following scheme is helpful to users of your package: add +0.1.0 if it is a breaking change, otherwise add +0.0.1. If you follow this scheme, let your users know!
  1. Publish to pub.dartlang.org! Give yourself a high five for helping launch Dart.

Thank you for your early support and your help to get ready for the launch.

Copied from original issue: joshi-stuff/cipher#29

implement scrypt

From @stevenroose on January 1, 2014 22:17

Feature request. Scrypt is a key deriviation function often used in the light of cryptocurrencies.
A Java implementation of scrypt can be found ar BouncyCastle: org.bouncycastle.crypto.generators.SCrypt

Copied from original issue: joshi-stuff/cipher#31

It's not possible to compress an ECPoint (using Fp) like it is in BouncyCastle

From @stevenroose on January 21, 2014 23:39

Did you skip the ECPoint.Fp() method from BouncyCastle on purpose?

There is currently no way to compress an ECPoint, neither using the ECPoint or the ECCurve class.

If compression can be achieved using the ECPoint.createPoint(BigInteger x, BigInteger y, [bool withCompression = false]) method by using uncompressed x and y and setting the flag to true (which I doubt), please specify it in the documentation.

Copied from original issue: joshi-stuff/cipher#47

Refactor the factories

From @izaera on November 3, 2013 9:8

Create an ext.dart library with the API for extending cipher (so that it does not appear in api.dart).

Refactor factories as a class instead of many hashmaps and functions.

This will make, IMO, things clearer and easier to use and maintain.

Copied from original issue: joshi-stuff/cipher#24

RSA signing

From @devoncarew on January 19, 2014 17:37

This is a feature request to have an RSA signing algorithm. Specifically, I need to be able to:

  • create an RSA public and private key
  • send a client the public key
  • given a token from the client, sign it with my private key

Thanks!

Copied from original issue: joshi-stuff/cipher#43

Split impl.dart into client and server parts (was 'dart:io dependency in v0.5.0')

From @devoncarew on January 15, 2014 17:37

We're using this package in the context of a web app (actually a chrome app). The latest version has introduced a dependency on dart:io. We've temporarily pegged our version dependency at 0.4.0.

packages/cipher/entropy/url_entropy_source.dart:9:8: Error: Library not found 'dart:io'.
import "dart:io";

Any chance this dart:io dependency could be removed, or only included from a cipher_io.dart entry-point?

Copied from original issue: joshi-stuff/cipher#41

a way to encrypt/decrypt data of arbitrary length

From @stevenroose on January 26, 2014 0:27

BC uses a CipherStream, I think.

I'm not sure if Dart has something as a ByteStream that could be underlying this. But it might be cumbersome to split your input data into multiple blocks to use the processBlock() method.

I'm not sure of a Uint8List BlockCipher.processData(Uint8List input) is possible?

Copied from original issue: joshi-stuff/cipher#49

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.