ninja 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

ninja #

Encryption and Decryption cryptographic algorithms exposed as Dart's Converter and Codec interfaces.

AES #

AES is symmetric-key encryption algorithm. Class AES implements Converter<String, String> to encrypt and decrypt data. It expects a key. By default, PKCS7Padded is used for padding. This can be configured using padder parameter.

Encryption #

Use encode method to encode clear text.

main() {
  final aes = AES.fromBytes(Uint8List.fromList(List.generate(16, (i) => i)));
  String value = aes.encode('Dart');
  print(value);
}

Decryption #

Use decode method to decode to clear text.

main() {
  final aes = AES.fromBytes(Uint8List.fromList(List.generate(16, (i) => i)));
  String decoded = aes.decode('3347391e8789852b5c1b6ff1d3c44d0c');
  print(decoded);
}

RSA #

RSA is an asymmetric-key encryption algorithm. Class RSA implements Converter<String, String> to encrypt and decrypt data.

It expects a key. If the key is RSAPublicKey, it can only encode. If the key is RSAPrivateKey, it can both encode and decode.

Encryption #

main() {
  final key = RSAPublicKey(
      BigInt.parse(
          "20620915813302906913761247666337410938401372343750709187749515126790853245302593205328533062154315527282056175455193812046134139935830222032257750866653461677566720508752544506266533943725970345491747964654489405936145559121373664620352701801574863309087932865304205561439525871868738640172656811470047745445089832193075388387376667722031640892525639171016297098395245887609359882693921643396724693523583076582208970794545581164952427577506035951122669158313095779596666008591745562008787129160302313244329988240795948461701615228062848622019620094307696506764461083870202605984497833670577046553861732258592935325691"),
      BigInt.parse("65537"));
    final rsa = RSA(key);
    String encoded =
        rsa.encode('Lorem ipsum dolor sit amet, consectetur adipiscing elit...');
    print(encoded);
}

Decryption #

main() {
  final key = RSAPrivateKey(
      BigInt.parse(
          "20620915813302906913761247666337410938401372343750709187749515126790853245302593205328533062154315527282056175455193812046134139935830222032257750866653461677566720508752544506266533943725970345491747964654489405936145559121373664620352701801574863309087932865304205561439525871868738640172656811470047745445089832193075388387376667722031640892525639171016297098395245887609359882693921643396724693523583076582208970794545581164952427577506035951122669158313095779596666008591745562008787129160302313244329988240795948461701615228062848622019620094307696506764461083870202605984497833670577046553861732258592935325691"),
      BigInt.parse("65537"),
      BigInt.parse(
          "11998058528661160053642124235359844880039079149364512302169225182946866898849176558365314596732660324493329967536772364327680348872134489319530228055102152992797567579226269544119435926913937183793755182388650533700918602627770886358900914370472445911502526145837923104029967812779021649252540542517598618021899291933220000807916271555680217608559770825469218984818060775562259820009637370696396889812317991880425127772801187664191059506258517954313903362361211485802288635947903604738301101038823790599295749578655834195416886345569976295245464597506584866355976650830539380175531900288933412328525689718517239330305"),
      BigInt.parse(
          "144173682842817587002196172066264549138375068078359231382946906898412792452632726597279520229873489736777248181678202636100459215718497240474064366927544074501134727745837254834206456400508719134610847814227274992298238973375146473350157304285346424982280927848339601514720098577525635486320547905945936448443"),
      BigInt.parse(
          "143028293421514654659358549214971921584534096938352096320458818956414890934365483375293202045679474764569937266017713262196941957149321696805368542065644090886347646782188634885321277533175667840285448510687854061424867903968633218073060468434469761149335255007464091258725753837522484082998329871306803923137"));

  final rsa = RSA(key);
  String decoded = rsa.decode(encoded);
  print(decoded);
}

2.0.1 #

  • Pub publish fixes

2.0.0 #

  • Port to Dart 2.0.0

1.0.0 #

  • Architecture
  • Added
    • AES
    • RSA

example/example.dart

import 'package:ninja/ninja.dart';

main() {
  final pubKey = RSAPublicKey(
      BigInt.parse(
          "20620915813302906913761247666337410938401372343750709187749515126790853245302593205328533062154315527282056175455193812046134139935830222032257750866653461677566720508752544506266533943725970345491747964654489405936145559121373664620352701801574863309087932865304205561439525871868738640172656811470047745445089832193075388387376667722031640892525639171016297098395245887609359882693921643396724693523583076582208970794545581164952427577506035951122669158313095779596666008591745562008787129160302313244329988240795948461701615228062848622019620094307696506764461083870202605984497833670577046553861732258592935325691"),
      BigInt.parse("65537"));

  final key = RSAPrivateKey(
      BigInt.parse(
          "20620915813302906913761247666337410938401372343750709187749515126790853245302593205328533062154315527282056175455193812046134139935830222032257750866653461677566720508752544506266533943725970345491747964654489405936145559121373664620352701801574863309087932865304205561439525871868738640172656811470047745445089832193075388387376667722031640892525639171016297098395245887609359882693921643396724693523583076582208970794545581164952427577506035951122669158313095779596666008591745562008787129160302313244329988240795948461701615228062848622019620094307696506764461083870202605984497833670577046553861732258592935325691"),
      BigInt.parse("65537"),
      BigInt.parse(
          "11998058528661160053642124235359844880039079149364512302169225182946866898849176558365314596732660324493329967536772364327680348872134489319530228055102152992797567579226269544119435926913937183793755182388650533700918602627770886358900914370472445911502526145837923104029967812779021649252540542517598618021899291933220000807916271555680217608559770825469218984818060775562259820009637370696396889812317991880425127772801187664191059506258517954313903362361211485802288635947903604738301101038823790599295749578655834195416886345569976295245464597506584866355976650830539380175531900288933412328525689718517239330305"),
      BigInt.parse(
          "144173682842817587002196172066264549138375068078359231382946906898412792452632726597279520229873489736777248181678202636100459215718497240474064366927544074501134727745837254834206456400508719134610847814227274992298238973375146473350157304285346424982280927848339601514720098577525635486320547905945936448443"),
      BigInt.parse(
          "143028293421514654659358549214971921584534096938352096320458818956414890934365483375293202045679474764569937266017713262196941957149321696805368542065644090886347646782188634885321277533175667840285448510687854061424867903968633218073060468434469761149335255007464091258725753837522484082998329871306803923137"));

  final rsa = RSA(key);
  String encoded =
      rsa.encode('Lorem ipsum dolor sit amet, consectetur adipiscing elit...');
  print(encoded);
  String decoded = rsa.decode(encoded);
  print(decoded);
}

Use this package as a library

1. Depend on it

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


dependencies:
  ninja: ^2.0.1

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

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/symmetric/aes/engine.dart. (-0.50 points)

Analysis of lib/symmetric/aes/engine.dart reported 1 hint:

line 27 col 11: The declaration '_rounds' isn't referenced.

Fix lib/utils/ufixnum.dart. (-0.50 points)

Analysis of lib/utils/ufixnum.dart reported 1 hint:

line 219 col 27: The value of the field '_MAX_VALUE' isn't used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.1 <3.0.0
Dev dependencies
pedantic any
test ^1.3.0