crypto_keys 0.1.0

  • Readme
  • Changelog
  • Installing
  • 71

Build Status

A library for doing cryptographic signing/verifying and encrypting/decrypting.

It uses pointycastle under the hood, but exposes a more convenient api.

Usage #

Signing #

A simple usage example:

import 'package:crypto_keys/crypto_keys.dart';
import 'dart:typed_data';

main() {
  // Create a key pair from a JWK representation
  var keyPair = new KeyPair.fromJwk({
    "kty": "oct",
    "k": "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75"
        "aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow"
  });

  // A key pair has a private and public key, possibly one of them is null, if
  // required info was not available when construction
  // The private key can be used for signing
  var privateKey = keyPair.privateKey;

  // Create a signer for the key using the HMAC/SHA-256 algorithm
  var signer = privateKey.createSigner(algorithms.signing.hmac.sha256);

  // Sign some content, to be integrity protected
  var content = "It's me, really me";
  var signature = signer.sign("It's me, really me".codeUnits);

  print("Signing '$content'");
  print("Signature: ${signature.data}");

  // The public key can be used for verifying the signature
  var publicKey = keyPair.publicKey;

  // Create a verifier for the key using the specified algorithm
  var verifier = publicKey.createVerifier(algorithms.signing.hmac.sha256);

  var verified =
      verifier.verify(new Uint8List.fromList(content.codeUnits), signature);
  if (verified)
    print("Verification succeeded");
  else
    print("Verification failed");
}

Encryption #

A simple usage example:


import 'package:crypto_keys/crypto_keys.dart';
import 'dart:typed_data';

main() {
  // Generate a new random symmetric key pair
  var keyPair = new KeyPair.generateSymmetric(128);

  // Use the public key to create an encrypter with the AES/GCM algorithm
  var encrypter =
      keyPair.publicKey.createEncrypter(algorithms.encryption.aes.gcm);

  // Encrypt the content with an additional authentication data for integrity
  // protection
  var content = "A very secret text";
  var aad = "It is me";
  var v = encrypter.encrypt(new Uint8List.fromList(content.codeUnits),
      additionalAuthenticatedData: new Uint8List.fromList(aad.codeUnits));

  print("Encrypting '$content'");
  print("Ciphertext: ${v.data}");
  print("Authentication tag: ${v.authenticationTag}");

  // Use the private key to create the decrypter
  var decrypter =
      keyPair.privateKey.createEncrypter(algorithms.encryption.aes.gcm);

  // Decrypt and verify authentication tag
  var decrypted = decrypter.decrypt(v);

  print("Decrypted text: '${new String.fromCharCodes(decrypted)}'");
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.0 #

  • Initial version

Use this package as a library

1. Depend on it

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


dependencies:
  crypto_keys: ^0.1.0

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:crypto_keys/crypto_keys.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
68
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/algorithms.dart. (-25 points)

Analysis of lib/src/algorithms.dart reported 70 hints, including:

line 17 col 20: Unnecessary new keyword.

line 21 col 19: Unnecessary new keyword.

line 24 col 22: Unnecessary new keyword.

line 26 col 30: Unnecessary new keyword.

line 28 col 13: Unnecessary new keyword.

Fix lib/src/impl.g.dart. (-25 points)

Analysis of lib/src/impl.g.dart reported 63 hints, including:

line 26 col 8: Unnecessary new keyword.

line 30 col 7: DO use curly braces for all flow control structures.

line 30 col 13: Unnecessary new keyword.

line 32 col 7: DO use curly braces for all flow control structures.

line 32 col 13: Unnecessary new keyword.

Fix lib/src/pointycastle_ext.dart. (-18.98 points)

Analysis of lib/src/pointycastle_ext.dart reported 42 hints, including:

line 35 col 25: Unnecessary new keyword.

line 43 col 19: Unnecessary new keyword.

line 50 col 21: Unnecessary new keyword.

line 63 col 33: Unnecessary new keyword.

line 73 col 20: Unnecessary new keyword.

Fix additional 5 files with analysis or formatting issues. (-35.34 points)

Additional issues in the following files:

  • lib/src/asymmetric_operator.dart (27 hints)
  • lib/src/keys.dart (21 hints)
  • lib/src/symmetric_operator.dart (13 hints)
  • lib/src/impl.dart (10 hints)
  • lib/src/symmetric_keys.dart (3 hints)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (built_value).

Package is getting outdated. (-21.64 points)

The package was last published 63 weeks ago.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

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

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
built_collection ^4.0.0 4.3.2
built_value ^6.1.5 6.8.2 7.0.8
meta ^1.1.6 1.1.8
pointycastle ^1.0.0-rc4 1.0.2
Transitive dependencies
analyzer 0.38.5 0.39.4
analyzer_plugin 0.2.1
args 1.5.2
async 2.4.0
build 1.2.2
build_config 0.4.1+1
built_value_generator 6.8.2 7.0.8
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
fixnum 0.10.11
front_end 0.1.27 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
json_annotation 3.0.1
kernel 0.3.27 0.3.29
logging 0.11.4
matcher 0.12.6
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.1.2+1
source_gen 0.9.4+6 0.9.4+7
source_span 1.6.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
test ^1.0.0