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

outdated

This dart package allows easy encryption of text using AEAD XChaCha20 Poly1305 and XChaCha20.

example/lib/example.dart

import 'package:flutter/cupertino.dart';
import 'package:prefix_encrypt/prefix_encrypt.dart';
import 'package:prefix_encrypt/without_prefix_encrypt.dart';

void main () {
  // all values have to be in hexadecimal

  String aad = "000000000000000000000000"; // must be at least 1 character
  String key = "0000000000000000000000000000000000000000000000000000000000000000"; // Key must be 64 character
  String iv = "0000000000000000"; // must be at least 16 character
  String constant = "00000000"; // must be 8 character
  String hNonce = "000000000000000000000000000000000000000000000000"; // must be 48 character
  String plaintextPrefix = "Hello World!😄";
  String plaintextWithoutPrefix = "Hello World!";
  void aeadXchacha20poly1305prefix() {
    List encrypt =
    AEADxChaCha20poly1305withPrefix.encrypt(aad: aad, iv: iv, key: key, constant: constant, hNonce: hNonce, plaintext: plaintextPrefix);
    String decrypt = AEADxChaCha20poly1305withPrefix.decrypt(
        aad: aad, iv: iv, key: key, constant: constant, hNonce: hNonce, ciphertext: encrypt[0], savedTag: encrypt[1]);
    debugPrint("$encrypt\n$decrypt");
  }

  void xChaChaPrefix() {
    String encrypt = XChaCha20withPrefix.encrypt(key: key, nonce: hNonce, plaintext: plaintextPrefix);
    String decrypt = XChaCha20withPrefix.decrypt(key: key, nonce: hNonce, ciphertext: encrypt);
    debugPrint("$encrypt\n$decrypt");
  }

  void aeadXchacha20poly1305() {
    List encrypt = AEADxChaCha20poly1305.encrypt(aad: aad, iv: iv, key: key, constant: constant, hNonce: hNonce, plaintext: plaintextWithoutPrefix);
    String decrypt =
    AEADxChaCha20poly1305.decrypt(aad: aad, iv: iv, key: key, constant: constant, hNonce: hNonce, ciphertext: encrypt[0], savedTag: encrypt[1]);
    debugPrint("$encrypt\n$decrypt");
  }

  void xChaCha20() {
    String encrypt = XChaCha20.encrypt(key: key, nonce: hNonce, plaintext: plaintextWithoutPrefix);
    String decrypt = XChaCha20.decrypt(key: key, nonce: hNonce, ciphertext: encrypt);
    debugPrint("$encrypt\n$decrypt");
  }

  aeadXchacha20poly1305prefix();
  xChaChaPrefix();
  aeadXchacha20poly1305();
  xChaCha20();
}
2
likes
50
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

This dart package allows easy encryption of text using AEAD XChaCha20 Poly1305 and XChaCha20.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

collection, flutter, material_color_utilities, meta, stack_trace, stream_channel, test_api

More

Packages that depend on prefix_encrypt