encrypt 0.2.0+1

encrypt #

Pub Package Build Status Donate

A set of high-level APIs over PointyCastle for two-way cryptography.

Looking for password hashing? Please, visit password.

AES (Block Cipher) #

import 'package:encrypt/encrypt.dart';

void main() {
  final key = 'my32lengthsupersecretnooneknows1';

  final encrypter = new Encrypter(new AES(key));
  final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ........';

  final encryptedText = encrypter.encrypt(plainText);
  final decryptedText = encrypter.decrypt(encryptedText);

  print(encryptedText); // db066ce180f62f020617eb720b891c1efcc48b217cb83272812a8efe3b30e7eae4373ddcede4ea77bdae77d126d95457b3759b1983bf4cb4a6a5b051a5690bdf
  print(decryptedText); // Lorem ipsum dolor sit amet, consectetur adipiscing elit ........

Salsa20 (Stream Cipher) #

import 'package:encrypt/encrypt.dart';

void main() {
  final key = 'private!!!!!!!!!';
  final iv = '8bytesiv'; // https://en.wikipedia.org/wiki/Initialization_vector
  final plainText = 'Secret';

  final encrypter = new Encrypter(new Salsa20(key, iv));

  final encrypted = encrypter.encrypt(plainText);
  final decrypted = encrypter.decrypt(encrypted);

  print(encrypted); // c5cc91943cf0
  print(decrypted); // Secret

Salsa20 With Chinese #

import 'package:encrypt/encrypt.dart';

void main() {
  final key = '1234567890123456';
  final iv = '8bytesiv';
  final encryptor = Encrypter(Salsa20(key, iv));
  String text = '你好';
  String base64Text = base64.encode(utf8.encode(text));
  String encText  = encryptor.encrypt(base64Text);
  var decStr = utf8.decode(base64.decode(encryptor.decrypt(encText)));

  print('enc text:'+encText);//c72f29fd34b15145
  print('dec text:'+decStr);//你好

RSA (Asymmetric) #


Use this package as a library

1. Depend on it

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

  encrypt: ^0.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:encrypt/encrypt.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Health suggestions

Fix lib/src/salsa20.dart. (-3.45 points)

Analysis of lib/src/salsa20.dart reported 7 hints, including:

line 16 col 33: Unnecessary new keyword.

line 19 col 19: Unnecessary new keyword.

line 20 col 13: Unnecessary new keyword.

line 20 col 30: Unnecessary new keyword.

line 21 col 13: Unnecessary new keyword.

Fix lib/src/aes.dart. (-2.96 points)

Analysis of lib/src/aes.dart reported 6 hints, including:

line 12 col 33: Unnecessary new keyword.

line 15 col 19: Unnecessary new keyword.

line 15 col 36: Unnecessary new keyword.

line 22 col 19: Unnecessary new keyword.

line 36 col 12: Unnecessary new keyword.

Fix lib/src/helpers.dart. (-1 points)

Analysis of lib/src/helpers.dart reported 2 hints:

line 4 col 16: Unnecessary new keyword.

line 13 col 16: Unnecessary new keyword.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Package is getting outdated. (-55.07 points)

The package was last published 80 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 encrypt.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
pointycastle ^1.0.0-rc4 1.0.2
Dev dependencies
test ^1.3.4