cipherlib 0.0.10 copy "cipherlib: ^0.0.10" to clipboard
cipherlib: ^0.0.10 copied to clipboard

retracted

Implementations of cryptographic algorithms for encryption and decryption in Dart.

cipherlib #

plugin version dart support likes pub points popularity

Implementations of cryptographic algorithms for encryption and decryption in Dart.

Depencencies #

There are only 2 dependencies used by this package:

Features #

Ciphers Public class and methods Source
AES AES, NIST.FIPS.197
XOR XOR, xor, xorStream Wikipedia
ChaCha20 ChaCha20, chacha20, chacha20Stream RFC-8439
ChaCha20/Poly1305 ChaCha20Poly1305, chacha20poly1305, chacha20poly1305Stream RFC-8439
Salsa20 Salsa20, salsa20, salsa20Stream Snuffle-2005
Salsa20/Poly1305 Salsa20Poly1305, salsa20poly1305, salsa20poly1305Stream Snuffle-2005

Available modes for AES:

  • ECB : Electronic Codeblock
  • CBC : Cipher Block Chaining
  • CTR : Counter
  • GCM : Galois/Counter Mode
  • CFB : Cipher Feedback
  • OFB : Output Feedback
  • PCBC : Propagating Cipher Block Chaining
  • XTS : XEX (XOR-Encrypt-XOR) Tweakable Block Cipher with Ciphertext Stealing

Getting started #

The following import will give you access to all of the algorithms in this package.

import 'package:cipherlib/cipherlib.dart';

Check the API Reference for details.

Usage #

Examples can be found inside the example folder.

import 'package:cipherlib/cipherlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

void main() {
  print('----- AES -----');
  {
    var plain = 'A not very secret message';
    var key = 'abcdefghijklmnopabcdefghijklmnop'.codeUnits;
    var iv = 'lka9JLKasljkdPsd'.codeUnits;
    print('  Text: $plain');
    print('   Key: ${toHex(key)}');
    print(' Nonce: ${toHex(iv)}');
    print('  ECB: ${toHex(AES(key).ecb().encryptString(plain))}');
    print('  CBC: ${toHex(AES(key).cbc(iv).encryptString(plain))}');
    print('  CTR: ${toHex(AES(key).ctr(iv).encryptString(plain))}');
    print('  GCM: ${toHex(AES(key).gcm(iv).encryptString(plain))}');
    print('  CFB: ${toHex(AES(key).cfb(iv).encryptString(plain))}');
    print('  OFB: ${toHex(AES(key).ofb(iv).encryptString(plain))}');
    print('  XTS: ${toHex(AES(key).xts(iv).encryptString(plain))}');
    print(' PCBC: ${toHex(AES(key).pcbc(iv).encryptString(plain))}');
  }
  print('');

  print('----- XOR -----');
  {
    var key = [0x54];
    var inp = [0x03, 0xF1];
    var cipher = xor(inp, key);
    var plain = xor(cipher, key);
    print('  Text: ${toBinary(inp)}');
    print('   Key: ${toBinary(key)}');
    print('   XOR: ${toBinary(cipher)}');
    print(' Plain: ${toBinary(plain)}');
  }
  print('');

  print('----- ChaCha20 -----');
  {
    var text = "Hide me!";
    var key = fromHex(
        "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
    var nonce = fromHex("00000000000000004a000000");
    var res = chacha20poly1305(toUtf8(text), key, nonce: nonce);
    var plain = chacha20(res.data, key, nonce: nonce);
    print('  Text: $text');
    print('   Key: ${toHex(key)}');
    print(' Nonce: ${toHex(nonce)}');
    print('Cipher: ${toHex(res.data)}');
    print('   Tag: ${res.tag.hex()}');
    print(' Plain: ${fromUtf8(plain)}');
  }
  print('');

  print('----- Salsa20 -----');
  {
    var text = "Hide me!";
    var key = fromHex(
        "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
    var nonce = fromHex("00000000000000004a00000000000000");
    var res = salsa20poly1305(toUtf8(text), key, nonce: nonce);
    var plain = salsa20(res.data, key, nonce: nonce);
    print('  Text: $text');
    print('   Key: ${toHex(key)}');
    print(' Nonce: ${toHex(nonce)}');
    print('Cipher: ${toHex(res.data)}');
    print('   Tag: ${res.tag.hex()}');
    print(' Plain: ${fromUtf8(plain)}');
  }
}

Benchmarks #

Libraries:

With 5MB message (10 iterations):

Algorithms cipherlib PointyCastle cryptography
XOR 241MB/s
ChaCha20 107.60MB/s 30.48MB/s
253% slower
ChaCha20/Poly1305 75.32MB/s 33.24MB/s
127% slower
ChaCha20/Poly1305(digest) 247.47MB/s
Salsa20 107.24MB/s 27.91MB/s
284% slower
Salsa20/Poly1305 76.42MB/s
Salsa20/Poly1305(digest) 248.50MB/s

With 1KB message (5000 iterations):

Algorithms cipherlib PointyCastle cryptography
XOR 250.20MB/s
ChaCha20 108.38MB/s 30.87MB/s
251% slower
ChaCha20/Poly1305 71.48MB/s 31.39MB/s
128% slower
ChaCha20/Poly1305(digest) 213.58MB/s
Salsa20 108.21MB/s 29.29MB/s
269% slower
Salsa20/Poly1305 72.17MB/s
Salsa20/Poly1305(digest) 217.38MB/s

With 10B message (100000 iterations):

Algorithms cipherlib PointyCastle cryptography
XOR 185.62MB/s
ChaCha20 32.03MB/s 3.91MB/s
719% slower
ChaCha20/Poly1305 9.71MB/s 4.14MB/s
134% slower
ChaCha20/Poly1305(digest) 14.31MB/s
Salsa20 32.33MB/s 3.81MB/s
748% slower
Salsa20/Poly1305 9.81MB/s
Salsa20/Poly1305(digest) 14.25MB/s

All benchmarks are done on AMD Ryzen 7 5800X processor and 3200MHz RAM using compiled exe

Dart SDK version: 3.3.3 (stable) (Tue Mar 26 14:21:33 2024 +0000) on "windows_x64"

4
likes
0
points
60
downloads

Publisher

unverified uploader

Weekly Downloads

Implementations of cryptographic algorithms for encryption and decryption in Dart.

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

paypal.me

License

unknown (license)

Dependencies

hashlib, hashlib_codecs

More

Packages that depend on cipherlib