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

retracted

Implementations of cryptographic algorithms for encryption and decryption in Dart.

cipherlib #

plugin version dependencies dart support likes pub points popularity

Implementations of cryptographic algorithms for encryption and decryption in Dart.

Features #

Ciphers Public class and methods Source
ChaCha20 ChaCha20, chacha20, chacha20Pipe RFC-8439
ChaCha20/Poly1305 ChaCha20Poly1305, chacha20poly1305, chacha20poly1305digest RFC-8439
XOR XOR, xor, xorPipe Wikipedia

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 'dart:convert';

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

void main() {
  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('----- ChaCha20 -----');
  {
    var text = "Hide me!";
    var key = fromHex(
        "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
    var nonce = fromHex("000000000000004a00000000");
    var result = chacha20poly1305(utf8.encode(text), key, nonce: nonce);
    var plain = chacha20poly1305(
      result.cipher,
      key,
      nonce: nonce,
      tag: result.tag.bytes,
    );
    print('  Text: $text');
    print('   Key: ${toHex(key)}');
    print(' Nonce: ${toHex(nonce)}');
    print('Cipher: ${toHex(result.cipher)}');
    print('   Tag: ${result.tag.hex()}');
    print(' Plain: ${utf8.decode(plain.cipher)}');
  }
}

Benchmarks #

Libraries:

With 5MB message (10 iterations):

Algorithms cipherlib
XOR 235.83MB/s
ChaCha20 108.76MB/s
ChaCha20/Poly1305 76.83MB/s
ChaCha20/Poly1305(digest) 249.10MB/s

With 1KB message (5000 iterations):

Algorithms cipherlib
XOR 257.71MB/s
ChaCha20 112.43MB/s
ChaCha20/Poly1305 74.40MB/s
ChaCha20/Poly1305(digest) 210.84MB/s

With 10B message (100000 iterations):

Algorithms cipherlib
XOR 183.72MB/s
ChaCha20 30.74MB/s
ChaCha20/Poly1305 9.59MB/s
ChaCha20/Poly1305(digest) 14.06MB/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