gainer_crypto 0.0.6 copy "gainer_crypto: ^0.0.6" to clipboard
gainer_crypto: ^0.0.6 copied to clipboard

A Library that can produce Cryptographic hash or can encrypt and decrypt text with key.

example/README.md

Crypto #

Hash #

import 'package:gainer_crypto/crypto.dart';

void main() {
  const inputText = "Hello GaiNeR";

  // Get Hash String of any CryptoType
  final sha1Hash = grHashString(GRCryptoType.sha1, inputText);
  print(sha1Hash);
  final md5Hash = grHashString(GRCryptoType.md5, inputText);
  print(md5Hash);

  // Get Hash Bytes in terms of List<int> of any CryptoType
  final sha1Bytes = grHashBytes(GRCryptoType.sha1, inputText);
  print(sha1Bytes);
  final md5Bytes = grHashBytes(GRCryptoType.md5, inputText);
  print(md5Bytes);

  const input1 = "Hello";
  const input2 = "GaiNeR";
  final chunks = [input1, input2];

  // Get Hash String of any CryptoType from chunks of String
  final sha256Hash = grHashStringFromArray(GRCryptoType.sha256, chunks);
  print(sha256Hash);
  final md4Hash = grHashStringFromArray(GRCryptoType.md4, chunks);
  print(md4Hash);

  // Get Hash Bytes in terms of List<int> of any CryptoType from chunks of String
  final sha256Bytes = grHashBytesFromArray(GRCryptoType.sha256, chunks);
  print(sha256Bytes);
  final md4Bytes = grHashBytesFromArray(GRCryptoType.md4, chunks);
  print(md4Bytes);
}

HMAC #

import 'package:gainer_crypto/crypto.dart';

void main() {
  const inputText = "Hello GaiNeR";

  // HMAC Examples where you need a key
  const key = "Password";

  // Get Hash String of any CryptoType
  final sha1HashHMAC =
      grHMACHashString(GRCryptoTypeHMAC.hmacSHA1, inputText, key);
  print(sha1HashHMAC);

  // Get Hash Bytes in terms of List<int> of any CryptoType
  final md5BytesHMAC =
      grHMACHashBytes(GRCryptoTypeHMAC.hmacMD5, inputText, key);
  print(md5BytesHMAC);

  const input1 = "Hello";
  const input2 = "GaiNeR";
  final chunks = [input1, input2];

  // Get Hash String of any CryptoType from chunks of String
  final sha256HashHMAC =
      grHMACHashStringFromArray(GRCryptoTypeHMAC.hmacSHA256, chunks, key);
  print(sha256HashHMAC);

  // Get Hash Bytes in terms of List<int> of any CryptoType from chunks of String
  final sha256BytesHMAC =
      grHMACHashBytesFromArray(GRCryptoTypeHMAC.hmacSHA256, chunks, key);
  print(sha256BytesHMAC);
}

Advanced Crypto #

Advanced Hash #

import 'package:gainer_crypto/crypto_advanced.dart';

void main() {
  const inputText = "Hello GaiNeR";
  final listCryptoTypes = [GRCryptoType.sha1, GRCryptoType.md5];

  // Encrypt the input string sequentially the list of types provided and
  // return Hash String
  final hashString = grAdvHashString(listCryptoTypes, inputText);
  print(hashString);

  // Encrypt the input string sequentially the list of types provided and
  // return Hash Bytes in terms of List<int>
  final hashBytes = grAdvHashBytes(listCryptoTypes, inputText);
  print(hashBytes);

  const input1 = "Hello";
  const input2 = "GaiNeR";
  final chunks = [input1, input2];

  // Encrypt the chunks input string sequentially the list of types provided
  // and return Hash String
  final hashStringCh = grAdvHashStringFromArray(listCryptoTypes, chunks);
  print(hashStringCh);

  // Encrypt the chunks input string sequentially the list of types provided
  // and return Hash Bytes in terms of List<int>
  final hashBytesCH = grAdvHashBytesFromArray(listCryptoTypes, chunks);
  print(hashBytesCH);

  // Encrypt the input string multiple times of CryptoType provided and
  // return Hash String. Here 3 means repeat 3 times, which will actually
  // encrypt 4 times.
  final sha1HashWR = grHashStringWR(GRCryptoType.sha1, 3, inputText);
  print(sha1HashWR);

  // Encrypt the input string multiple times of CryptoType provided and
  // return Hash Bytes in terms of List<int>. Here 2 means repeat 2 times,
  // which will actually encrypt 3 times.
  final md5BytesWR = grHashBytesWR(GRCryptoType.md5, 2, inputText);
  print(md5BytesWR);

  // Encrypt the chunks input string multiple times of CryptoType provided and
  // return Hash String. Here 3 means repeat 3 times, which will actually
  // encrypt 4 times.
  final hashChunkWR = grHashStringFromArrayWR(GRCryptoType.sha1, 3, chunks);
  print(hashChunkWR);

  // Encrypt the chunks input string multiple times of CryptoType provided and
  // return Hash Bytes in terms of List<int>. Here 2 means repeat 2 times,
  // which will actually encrypt 3 times.
  final bytesChunkWR = grHashBytesFromArrayWR(GRCryptoType.md5, 2, chunks);
  print(bytesChunkWR);
}

Advanced HMAC #

import 'package:gainer_crypto/crypto_advanced.dart';

void main() {
  const inputText = "Hello GaiNeR";

  // HMAC Examples where you need a key
  const key = "Password";

  final listCryptoTypes = [GRCryptoTypeHMAC.hmacSHA1, GRCryptoTypeHMAC.hmacMD5];

  // Encrypt the input string sequentially the list of types provided and
  // return Hash String
  final hashString = grAdvHMACHashString(listCryptoTypes, inputText, key);
  print(hashString);

  // Encrypt the input string sequentially the list of types provided and
  // return Hash Bytes in terms of List<int>
  final hashBytes = grAdvHMACHashBytes(listCryptoTypes, inputText, key);
  print(hashBytes);

  const input1 = "Hello";
  const input2 = "GaiNeR";
  final chunks = [input1, input2];

  // Encrypt the chunks input string sequentially the list of types provided
  // and return Hash String
  final hashStringCh =
      grAdvHMACHashStringFromArray(listCryptoTypes, chunks, key);
  print(hashStringCh);

  // Encrypt the chunks input string sequentially the list of types provided
  // and return Hash Bytes in terms of List<int>
  final hashBytesCH = grAdvHMACHashBytesFromArray(listCryptoTypes, chunks, key);
  print(hashBytesCH);

  // Encrypt the input string multiple times of CryptoType provided and
  // return Hash String. Here 3 means repeat 3 times, which will actually
  // encrypt 4 times.
  final sha1HashWR =
      grHMACHashStringWR(GRCryptoTypeHMAC.hmacSHA1, 3, inputText, key);
  print(sha1HashWR);

  // Encrypt the input string multiple times of CryptoType provided and
  // return Hash Bytes in terms of List<int>. Here 2 means repeat 2 times,
  // which will actually encrypt 3 times.
  final md5BytesWR =
      grHMACHashBytesWR(GRCryptoTypeHMAC.hmacMD5, 2, inputText, key);
  print(md5BytesWR);

  // Encrypt the chunks input string multiple times of CryptoType provided and
  // return Hash String. Here 3 means repeat 3 times, which will actually
  // encrypt 4 times.
  final hashChunkWR =
      grHMACHashStringFromArrayWR(GRCryptoTypeHMAC.hmacSHA1, 3, chunks, key);
  print(hashChunkWR);

  // Encrypt the chunks input string multiple times of CryptoType provided and
  // return Hash Bytes in terms of List<int>. Here 2 means repeat 2 times,
  // which will actually encrypt 3 times.
  final bytesChunkWR =
      grHMACHashBytesFromArrayWR(GRCryptoTypeHMAC.hmacMD5, 2, chunks, key);
  print(bytesChunkWR);
}

Key Generation #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  // Creating Key

  // Generate key from a String
  GRKey key = grKeyFromUtf8("GaiNeR Password");

  // Generate key from a Base16 Encoded String
  key = grKeyFromBase16("<Base16 String>");

  // Generate key from a Base64 Encoded String
  key = grKeyFromBase64("<Base64 String>");

  // Generate key of an integer length
  key = grKeyFromLength(16);

  // Generate Secured Random key of an integer length
  key = grKeyFromSecureRandom(16);
}

IV Generation #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  // Creating IV

  // Generate iv from a String
  GRIV iv = grIVFromUtf8("GaiNeR Password");

  // Generate iv from a Base16 Encoded String
  iv = grIVFromBase16("<Base16 String>");

  // Generate iv from a Base64 Encoded String
  iv = grIVFromBase64("<Base64 String>");

  // Generate iv of an integer length
  iv = grIVFromLength(16);

  // Generate Secured Random iv of an integer length
  iv = grIVFromSecureRandom(16);
}

Encryption Decryption #

AES #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  const inputText = "Hello GaiNeR";

  // Make a key of Type GRKey
  GRKey key = grKeyFromUtf8("32 Length Key...");

  // AES Base64 Encryption and Decryption input and Key Mandatory
  String encrypted = grEncrypt64AES(input: inputText, key: key);
  String decrypted = grDecrypt64AES(inputBase64: encrypted, key: key);

  // You can pass specific mode of Type GRAESMode. Default is GRAESMode.sic
  encrypted = grEncrypt64AES(input: inputText, key: key, mode: GRAESMode.cbc);
  decrypted =
      grDecrypt64AES(inputBase64: encrypted, key: key, mode: GRAESMode.cbc);

  // You can pass specific padding of Type GRPadding. Default is GRPadding.pkcs7
  encrypted =
      grEncrypt64AES(input: inputText, key: key, padding: GRPadding.none);
  decrypted =
      grDecrypt64AES(inputBase64: encrypted, key: key, padding: GRPadding.none);

  // You can pass repeat count. Default is 0. and Negative not allowed
  // By default it will be encrypted only once
  // Here it will be encrypted 3 times
  encrypted = grEncrypt64AES(input: inputText, key: key, repeat: 2);
  decrypted = grDecrypt64AES(inputBase64: encrypted, key: key, repeat: 2);

  // You can pass custom iv of type GRIV. Default is grIVFromLength(16)
  GRIV iv = grIVFromUtf8("16 Length IV...");
  encrypted = grEncrypt64AES(input: inputText, key: key, iv: iv);
  decrypted = grDecrypt64AES(inputBase64: encrypted, key: key, iv: iv);

  // All Param Together
  encrypted = grEncrypt64AES(
      input: inputText,
      key: key,
      iv: iv,
      mode: GRAESMode.ctr,
      padding: GRPadding.pkcs7,
      repeat: 3);
  decrypted = grDecrypt64AES(
      inputBase64: encrypted,
      key: key,
      iv: iv,
      mode: GRAESMode.ctr,
      padding: GRPadding.pkcs7,
      repeat: 3);
}

Fernet #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  const inputText = "Hello GaiNeR";

  // Make a key of Type GRKey
  GRKey key = grKeyFromUtf8("32 Length Key...");

  // Fernet Base64 Encryption and Decryption input and Key Mandatory
  String encrypted = grEncrypt64Fernet(input: inputText, key: key);
  String decrypted = grDecrypt64Fernet(inputBase64: encrypted, key: key);

  // You can pass repeat count. Default is 0. and Negative not allowed
  // By default it will be encrypted only once
  // Here it will be encrypted 3 times
  encrypted = grEncrypt64Fernet(input: inputText, key: key, repeat: 2);
  decrypted = grDecrypt64Fernet(inputBase64: encrypted, key: key, repeat: 2);

  // You can pass custom iv of type GRIV. Default is null
  GRIV iv = grIVFromUtf8("16 Length IV...");
  encrypted = grEncrypt64Fernet(input: inputText, key: key, iv: iv);
  decrypted = grDecrypt64Fernet(inputBase64: encrypted, key: key, iv: iv);

  // All Param Together
  encrypted = grEncrypt64Fernet(input: inputText, key: key, iv: iv, repeat: 3);
  decrypted =
      grDecrypt64Fernet(inputBase64: encrypted, key: key, iv: iv, repeat: 3);
}

Salsa20 #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  const inputText = "Hello GaiNeR";

  // Make a key of Type GRKey
  GRKey key = grKeyFromUtf8("32 Length Key...");

  // Salsa20 Base64 Encryption and Decryption input and Key Mandatory
  String encrypted = grEncrypt64Salsa20(input: inputText, key: key);
  String decrypted = grDecrypt64Salsa20(inputBase64: encrypted, key: key);

  // You can pass repeat count. Default is 0. and Negative not allowed
  // By default it will be encrypted only once
  // Here it will be encrypted 3 times
  encrypted = grEncrypt64Salsa20(input: inputText, key: key, repeat: 2);
  decrypted = grDecrypt64Salsa20(inputBase64: encrypted, key: key, repeat: 2);

  // You can pass custom iv of type GRIV. Default is grIVFromLength(8)
  GRIV iv = grIVFromUtf8("8 Length IV...");
  encrypted = grEncrypt64Salsa20(input: inputText, key: key, iv: iv);
  decrypted = grDecrypt64Salsa20(inputBase64: encrypted, key: key, iv: iv);

  // All Param Together
  encrypted = grEncrypt64Salsa20(input: inputText, key: key, iv: iv, repeat: 3);
  decrypted =
      grDecrypt64Salsa20(inputBase64: encrypted, key: key, iv: iv, repeat: 3);
}

RSA #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  const inputText = "Hello GaiNeR";
  const publicKeyPath = 'test/public.pem';
  const privateKeyPath = 'test/private.pem';

  // RSA Base 64Encryption and Decryption
  // input, publicKeyPath and privateKeyPath Mandatory
  String encrypted = "";
  grEncrypt64RSA(
      input: inputText,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath)
      .then((value) => {encrypted = value});
  String decrypted = "";
  grDecrypt64RSA(
      inputBase64: encrypted,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath)
      .then((value) => {decrypted = value});

  // You can pass repeat count. Default is 0. and Negative not allowed
  // By default it will be encrypted only once
  // Here it will be encrypted 3 times
  grEncrypt64RSA(
      input: inputText,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath,
      repeat: 2)
      .then((value) => {encrypted = value});
  grDecrypt64RSA(
      inputBase64: encrypted,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath,
      repeat: 2)
      .then((value) => {decrypted = value});

  // You can pass encoding GREncodingRSA. Default is GREncodingRSA.PKCS1
  grEncrypt64RSA(
      input: inputText,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath,
      encoding: GREncodingRSA.OAEP)
      .then((value) => {encrypted = value});
  grDecrypt64RSA(
      inputBase64: encrypted,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath,
      encoding: GREncodingRSA.OAEP)
      .then((value) => {decrypted = value});

  // All Param Together
  grEncrypt64RSA(
      input: inputText,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath,
      encoding: GREncodingRSA.OAEP,
      repeat: 2)
      .then((value) => {encrypted = value});
  grDecrypt64RSA(
      inputBase64: encrypted,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath,
      encoding: GREncodingRSA.OAEP,
      repeat: 2)
      .then((value) => {decrypted = value});
}

Signature Verification #

RSA Signing and Verification #

import 'package:gainer_crypto/encrypt_decrypt.dart';

void main() {
  const inputText = "Hello GaiNeR";
  const publicKeyPath = 'test/public.pem';
  const privateKeyPath = 'test/private.pem';

  // RSA Base64 Sign and Verification
  // For Signing input, publicKeyPath and privateKeyPath Mandatory
  String signedValue = "";
  grSign64RSA(
      input: inputText,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath)
      .then((value) => {signedValue = value});

  // For Verification input, signatureBase64, publicKeyPath and privateKeyPath Mandatory
  bool verified = false;
  grVerify64RSA(
      input: inputText,
      signatureBase64: signedValue,
      publicKeyPath: publicKeyPath,
      privateKeyPath: privateKeyPath)
      .then((value) => {verified = value});
}
7
likes
110
points
45
downloads

Documentation

API reference

Publisher

verified publishergnrtech.in

Weekly Downloads

A Library that can produce Cryptographic hash or can encrypt and decrypt text with key.

Homepage

License

unknown (license)

Dependencies

convert, crypto, encrypt, flutter, pointycastle

More

Packages that depend on gainer_crypto