rsa_pkcs 1.1.0

  • Readme
  • Changelog
  • Installing
  • 71

Build Status

rsa_pkcs #

RSA,PKCS#1,PKCS#8

openssl genrsa -out rsa_private_key.pem

openssl rsa -in rsa_private_key.pem -text -noout -out rsa_private_key.txt

openssl pkcs8 -in rsa_private_key.pem -topk8 -v2 aes-256-cbc -out rsa_enc_private_key.pem

openssl pkcs8 -in rsa_private_key.pem -topk8 -v2 aes-256-cbc -v2prf hmacWithSHA256 -out rsa_enc_private_key.pem
library rsa_pkcs_test;

import 'dart:io';
import 'package:test/test.dart';
import 'package:rsa_pkcs/rsa_pkcs.dart';

/// Test suite
void main() {
  test('rsa private key PKCS#1', () {
    //openssl genrsa -out rsa_private_key.pem
    //
    final File rsaPrivateKeyFile = File('test/resource/rsa_private_key.pem');
    final String pem = rsaPrivateKeyFile.readAsStringSync();
    final RSAPKCSParser parser = RSAPKCSParser();
    final RSAKeyPair pair = parser.parsePEM(pem);
    final RSAPrivateKey privateKey = pair.private;

    expect(pair.public, equals(null));
    expect(privateKey != null, equals(true));
    expect(privateKey.version, equals(0));
    final BigInt expectedModulus = BigInt.parse(
      '00d83c3cacb3b767a1020f947ca2012010ba494d86bda1efd437357b91d5c1e61b12384cd3c01f628312a5ef15cf003f62c4f6b835bbb3ea99409f87e583fa6991',
      radix: 16,
    );
    expect(privateKey.modulus, expectedModulus);
    expect(privateKey.publicExponent, equals(65537));

    final BigInt expectedPrivateComponent = BigInt.parse(
        '00a0c22fcda992b9cd5eeddc53c85193d83bd6917791f6198a293d6ecfde1e5885fbc0a766aaca385dd8b3b16a58201baec3900b5c1636321a0167e956d5fbe001',
        radix: 16);
    expect(privateKey.privateExponent, expectedPrivateComponent);
    expect(
        privateKey.prime1,
        BigInt.parse(
            '00f3103a1bb14f88f096983ecd86cb51f9e0e9325030039be4fbb4176de1b73f91',
            radix: 16));
    expect(
        privateKey.prime2,
        BigInt.parse(
            '00e3be793b593e4ed5bce5db1ff563468eeb5cc715b12badf223d1970cd88f8a01',
            radix: 16));
    expect(
        privateKey.exponent1,
        BigInt.parse(
            '7e4e8863ab98310914b8b8aa04c9d3278e809fec9b86c49411585c74753ecc81',
            radix: 16));
    expect(
        privateKey.exponent2,
        BigInt.parse(
            '687f8272f7ecfe11569e855ff1a17ec39f3d2fe0452e0c9f794df7281eca2601',
            radix: 16));
    expect(
        privateKey.coefficient,
        BigInt.parse(
            '0092e895c1a9b7b705fb694bba2d52cb9901d4628db794eb43861b086c557d2913',
            radix: 16));
  });

  test('rsa public key PKCS#8', () {
    //openssl genrsa -out rsa_private_key.pem
    //openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
    final File rsaPrivateKeyFile = File('test/resource/rsa_public_key.pem');
    final String pem = rsaPrivateKeyFile.readAsStringSync();
    final RSAPKCSParser parser = RSAPKCSParser();
    final RSAKeyPair pair = parser.parsePEM(pem);
    final RSAPrivateKey privateKey = pair.private;
    final RSAPublicKey publicKey = pair.public;

    expect(privateKey, equals(null));
    expect(publicKey != null, equals(true));

    expect(
        publicKey.modulus,
        BigInt.parse(
            '00d83c3cacb3b767a1020f947ca2012010ba494d86bda1efd437357b91d5c1e61b12384cd3c01f628312a5ef15cf003f62c4f6b835bbb3ea99409f87e583fa6991',
            radix: 16));
    expect(publicKey.publicExponent, equals(65537));
  });
}

1.0.0 #

  • Supports Dart 2
  • Upgraded dependencies
  • Removed dependency on pointycastle
  • Removed dependency on bignum (use BigInt from dart:core instead)

0.1.2 #

  • Supports Dart 1

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Maintenance suggestions

The package description is too short. (-20 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.

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 rsa_pkcs.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
asn1lib ^0.5.0 0.5.11
Dev dependencies
test ^1.0.0