Last updated:
0 purchases
gainer crypto
GaiNeR Crypto #
This is a package developed by GaiNeR Technologies to generate Common Cryptographic Hash.
Also It can encrypt or decrypt texts or String with some well known methods.
Features #
Cryptography
Common Hash
Create Hash String From Text
Create Hash Bytes From Text
Create Hash String From Chunk Of Texts
Create Hash Bytes From Chunk Of Texts
Common HMAC Hash
Create HMAC Hash String From Text
Create HMAC Hash Bytes From Text
Create HMAC Hash String From Chunk Of Texts
Create HMAC Hash Bytes From Chunk Of Texts
Advanced Cryptography
Advanced Hash
Create Hash String From Text by combining multiple methods
Create Hash Bytes From Text by combining multiple methods
Create Hash String From Chunk Of Texts by combining multiple methods
Create Hash Bytes From Chunk Of Texts by combining multiple methods
Create Hash String From Text by repeating one method multiple times
Create Hash Bytes From Text by repeating one method multiple times
Create Hash String From Chunk Of Texts by repeating one method multiple times
Create Hash Bytes From Chunk Of Texts by repeating one method multiple times
Advanced HMAC Hash
Create HMAC Hash String From Text by combining multiple methods
Create HMAC Hash Bytes From Text by combining multiple methods
Create HMAC Hash String From Chunk Of Texts by combining multiple methods
Create HMAC Hash Bytes From Chunk Of Texts by combining multiple methods
Create HMAC Hash String From Text by repeating one method multiple times
Create HMAC Hash Bytes From Text by repeating one method multiple times
Create HMAC Hash String From Chunk Of Texts by repeating one method multiple times
Create HMAC Hash Bytes From Chunk Of Texts by repeating one method multiple times
Key Generation For Encryption and Decryption
IV Generation For Encryption and Decryption
Encryption and Decryption `
AES
Fernet
Salsa20
RSA
RSA Sign and Verification
Getting started #
To use only the Common Cryptographic functions
import 'package:gainer_crypto/crypto.dart';
copied to clipboard
To use the Advanced Cryptographic functions
import 'package:gainer_crypto/crypto_advanced.dart';
copied to clipboard
To use the encryption decryption functions or the key generation
import 'package:gainer_crypto/encrypt_decrypt.dart';
copied to clipboard
To use all together
import 'package:gainer_crypto/gainer_crypto.dart';
copied to clipboard
Usage #
All functions from this library start with prefix gr. For eg.
grHashString(GRCryptoType type, String input);
copied to clipboard
Here grHashString is a function name.
All the class names and enum names start with prefix GR. For eg.
GRKey key = grKeyFromUtf8("32 Length Key...");
GRIV iv = grIVFromLength(16);
GRCryptoType hashType = GRCryptoType.md5;
GRCryptoTypeHMAC hmacHashType = GRCryptoTypeHMAC.hmacSHA1;
copied to clipboard
Here,
GRKey and GRIV are classes
GRCryptoType and "GRCryptoTypeHMAC" are enums
grKeyFromUtf8 and grIVFromLength are functions
Crypto #
Hash
We can encrypt an input text through a specific method (eg. SHA1, MD5 etc).
The hash generated in this process, can't be decrypted. For example,
final sha1Hash = grHashString(GRCryptoType.sha1, "inputText");
copied to clipboard
Here you can see the function grHashString takes two parameters,
* hashType: Specific Hash method, which should be of type *GRCryptoType*
* input: A string input to be encrypted
copied to clipboard
This function will convert the input String to sha1 hash as the hashType provided as GRCryptoType.sha1
The supported values of GRCryptoType enum are,
* sha1
* sha224
* sha256
* sha384
* sha512
* sha512_224
* sha512_256
* md5
* md2
* md4
* ripemd128
* ripemd160
* ripemd256
* ripemd320
* sha3_224
* sha3_256
* sha3_384
* sha3_512
* keccak224
* keccak256
* keccak384
* keccak512
* tiger
* whirlpool
* sm3
copied to clipboard
You can find more examples of Hashing in the Example Tab
HMAC
We can encrypt an input text through a specific method (eg. SHA1, MD5 etc) and a key.
Using the key to generate hash is called HMAC.
The hash generated in this process, can't be decrypted. For example,
const input = "inputText";
const key = "Password";
final md5Hash = grHMACHashString(GRCryptoTypeHMAC.hmacMD5, input, key);
copied to clipboard
Here you can see the function grHMACHashString takes two parameters,
* hashType: Specific Hash method, which should be of type *GRCryptoType*
* input: A string input to be encrypted
* key: A string key for extra security
copied to clipboard
This function will convert the input String to md5 hash as the hashType provided as GRCryptoTypeHMAC.hmacMD5
The supported values of GRCryptoTypeHMAC enum are,
* hmacSHA1,
* hmacSHA224,
* hmacSHA256,
* hmacSHA384,
* hmacSHA512,
* hmacSHA512_224,
* hmacSHA512_256,
* hmacMD5
copied to clipboard
You can find more examples of HMAC Hashing in the Example Tab
Advanced Crypto #
Advanced Hash
In the advanced section, we can encrypt one input string multiple times with different methods or with the same methods.
Also,the generated hash can't be decrypted. Now, look at the given example,
const inputText = "Hello GaiNeR";
final listCryptoTypes = [GRCryptoType.sha1, GRCryptoType.md5];
final hashString = grAdvHashString(listCryptoTypes, inputText);
print(hashString);
copied to clipboard
Here you can see, we are passing two parameters to the function grAdvHashString
* hashTypes: Which is a List of *GRCryptoType*
* input: A string input to be encrypted
copied to clipboard
This function will convert the input String twice, 1st in sha1 hash and 2nd the sha1 hash to md5 hash
as the hashTypes provided as GRCryptoType.sha1 and GRCryptoType.md5 sequentially in the List.
You can provide any number of GRCryptoType in the List. If a blank List is provided the output will be blank String.
* Note: Adv in grAdvHashString denotes the Advanced
copied to clipboard
Again, Look at this example,
const inputText = "Hello GaiNeR";
final sha1HashWR = grHashStringWR(GRCryptoType.sha1, 3, inputText);
print(sha1HashWR);
copied to clipboard
Here you can see, we are passing two parameters to the function grHashStringWR
* hashType: Specific Hash method, which should be of type *GRCryptoType*
* repeat: an integer, mentioning the repeat count
* input: A string input to be encrypted
copied to clipboard
1st this function will convert the input String to sha1 hash as the hashType provided as GRCryptoType.sha1.
Then output will be again encrypted in sha1 3 times as repeat count is 3.
If the repeat count is 0, then it will be encrypted only once and will not be repeated. So,
final sha1HashWR = grHashStringWR(GRCryptoType.sha1, 0, inputText);
copied to clipboard
is same as
final sha1Hash = grHashString(GRCryptoType.sha1, inputText);
copied to clipboard
If the repeat count is negative, the output will be blank String.
* Note: WR in grHashStringWR stands for With Repeat
copied to clipboard
You can find more examples of Advanced Hashing in the Example Tab
Advanced HMAC
In the advanced HMAC section, we can encrypt one input string multiple times with different methods or with the same methods.
As this is the HMAC we have to use one extra key for encryption.
Also,the generated hash can't be decrypted. Now, look at the given example,
const inputText = "Hello GaiNeR";
const key = "Password";
final listCryptoTypes = [GRCryptoTypeHMAC.hmacSHA1, GRCryptoTypeHMAC.hmacMD5];
final hashString = grAdvHMACHashString(listCryptoTypes, inputText, key);
print(hashString);
copied to clipboard
Here you can see, we are passing two parameters to the function grAdvHMACHashString
* hashTypes: Which is a List of *GRCryptoTypeHMAC*
* input: A string input to be encrypted
* key: A string key for extra security
copied to clipboard
This function will convert the input String twice, 1st in sha1 hash and 2nd the sha1 hash to md5 hash
as the hashTypes provided as GRCryptoTypeHMAC.hmacSHA1 and GRCryptoTypeHMAC.hmacMD5 sequentially in the List.
You can provide any number of GRCryptoTypeHMAC in the List. If a blank List is provided the output will be blank String.
* Note: Adv in grAdvHashString denotes the Advanced
copied to clipboard
Again, Look at this example,
const inputText = "Hello GaiNeR";
const key = "Password";
final sha1HashWR = grHMACHashStringWR(GRCryptoTypeHMAC.hmacSHA1, 3, inputText, key);
print(sha1HashWR);
copied to clipboard
Here you can see, we are passing two parameters to the function grHMACHashStringWR
* hashType: Specific Hash method, which should be of type *GRCryptoTypeHMAC*
* repeat: an integer, mentioning the repeat count
* input: A string input to be encrypted
* key: A string key for extra security
copied to clipboard
1st this function will convert the input String to sha1 hash as the hashType provided as GRCryptoTypeHMAC.hmacSHA1.
Then output will be again encrypted in sha1 3 times as repeat count is 3.
If the repeat count is 0, then it will be encrypted only once and will not be repeated. So,
final sha1HashWR = grHMACHashStringWR(GRCryptoTypeHMAC.hmacSHA1, 0, inputText, key);
copied to clipboard
is same as
final sha1Hash = grHMACHashString(GRCryptoTypeHMAC.hmacSHA1, inputText, key);
copied to clipboard
If the repeat count is negative, the output will be blank String.
* Note: WR in grHashStringWR stands for With Repeat
copied to clipboard
You can find more examples of Advanced HMAC Hashing in the Example Tab
Key Generation #
You can generate key of type GRKey for encryption and decryption. One example,
GRKey key = grKeyFromBase16("<Base16 String>");
copied to clipboard
You can find more examples of Key Generation in the Example Tab
IV Generation #
You can generate iv of type GRIV for encryption and decryption. One example,
GRIV iv = grIVFromUtf8("My Iv");
copied to clipboard
You can find more examples of IV Generation in the Example Tab
Encryption Decryption #
AES
In this method you can encrypt or decrypt the input String with a key.
For Encryption you can use,
Base16 Encryption Function
String grEncrypt16AES(
{required String input,
required GRKey key,
GRIV? iv,
GRAESMode mode = GRAESMode.sic,
GRPadding padding = GRPadding.pkcs7,
int repeat = 0});
copied to clipboard
This function returns a hex or base16 string
Base64 Encryption Function
String grEncrypt64AES(
{required String input,
required GRKey key,
GRIV? iv,
GRAESMode mode = GRAESMode.sic,
GRPadding padding = GRPadding.pkcs7,
int repeat = 0});
copied to clipboard
This function returns a base64 string
For Decryption you can use,
Base16 Decryption Function
dynamic grDecrypt16AES(
{required String inputBase16,
required GRKey key,
GRIV? iv,
GRAESMode mode = GRAESMode.sic,
GRPadding padding = GRPadding.pkcs7,
int repeat = 0});
copied to clipboard
The input should be hex or base16 String and returns a utf8 String
Base64 Decryption Function
dynamic grDecrypt64AES(
{required String inputBase64,
required GRKey key,
GRIV? iv,
GRAESMode mode = GRAESMode.sic,
GRPadding padding = GRPadding.pkcs7,
int repeat = 0});
copied to clipboard
The input should be base64 String and returns a utf8 String
For AES, you can see in all functions only two parameters are required input and key. Rests are optional.
Supported values of GRAESMode are,
* cbc
* cfb64
* ctr
* ecb
* ofb64Gctr
* ofb64
* sic
copied to clipboard
Default is GRAESMode.sic
Supported paddings of GRPadding type are,
* pkcs7
* none
copied to clipboard
Default is GRPadding.pkcs7
You can find more examples of AES in the Example Tab
In the examples only base64 encryption and decryption are shown. Similarly you can do for Base16.
Fernet
In this method you can encrypt or decrypt the input String with a key.
For Encryption you can use,
Base16 Encryption Function
String grEncrypt16Fernet({required String input, required GRKey key, GRIV? iv, int repeat = 0});
copied to clipboard
This function returns a hex or base16 string
Base64 Encryption Function
String grEncrypt64Fernet({required String input, required GRKey key, GRIV? iv, int repeat = 0});
copied to clipboard
This function returns a base64 string
For Decryption you can use,
Base16 Decryption Function
String grDecrypt16Fernet(
{required String inputBase16,
required GRKey key,
GRIV? iv,
int repeat = 0});
copied to clipboard
The input should be hex or base16 String and returns a utf8 String
Base64 Decryption Function
String grDecrypt64Fernet(
{required String inputBase64,
required GRKey key,
GRIV? iv,
int repeat = 0});
copied to clipboard
The input should be base64 String and returns a utf8 String
For Fernet, you can see in all functions only two parameters are required input and key. Rests are optional.
You can find more examples of Fernet in the Example Tab
In the examples only base64 encryption and decryption are shown. Similarly you can do for Base16.
Salsa20
In this method you can encrypt or decrypt the input String with a key.
For Encryption you can use,
Base16 Encryption Function
String grEncrypt16Salsa20({required String input, required GRKey key, GRIV? iv, int repeat = 0});
copied to clipboard
This function returns a hex or base16 string
Base64 Encryption Function
String grEncrypt64Salsa20({required String input, required GRKey key, GRIV? iv, int repeat = 0});
copied to clipboard
This function returns a base64 string
For Decryption you can use,
Base16 Decryption Function
String grDecrypt16Salsa20(
{required String inputBase16,
required GRKey key,
GRIV? iv,
int repeat = 0});
copied to clipboard
The input should be hex or base16 String and returns a utf8 String
Base64 Decryption Function
String grDecrypt64Salsa20(
{required String inputBase64,
required GRKey key,
GRIV? iv,
int repeat = 0});
copied to clipboard
The input should be base64 String and returns a utf8 String
For Salsa20, you can see in all functions only two parameters are required input and key. Rests are optional.
You can find more example of Salsa20 in the Example Tab
In the examples only base64 encryption and decryption are shown. Similarly you can do for Base16.
RSA
In this method you can encrypt or decrypt the input String with a public key and a private key.
For Encryption you can use,
Base16 Encryption Function
Future<String> grEncrypt16RSA(
{required String input,
required String publicKeyPath,
required String privateKeyPath,
GREncodingRSA encoding = GREncodingRSA.PKCS1,
int repeat = 0});
copied to clipboard
This function returns a hex or base16 string
Base64 Encryption Function
Future<String> grEncrypt64RSA(
{required String input,
required String publicKeyPath,
required String privateKeyPath,
GREncodingRSA encoding = GREncodingRSA.PKCS1,
int repeat = 0});
copied to clipboard
This function returns a base64 string
For Decryption you can use,
Base16 Decryption Function
Future<String> grDecrypt16RSA(
{required String inputBase16,
required String publicKeyPath,
required String privateKeyPath,
GREncodingRSA encoding = GREncodingRSA.PKCS1,
int repeat = 0});
copied to clipboard
The input should be hex or base16 String and returns a utf8 String
Base64 Decryption Function
Future<String> grDecrypt64RSA(
{required String inputBase64,
required String publicKeyPath,
required String privateKeyPath,
GREncodingRSA encoding = GREncodingRSA.PKCS1,
int repeat = 0});
copied to clipboard
The input should be base64 String and returns a utf8 String
For RSA, you can see in all functions three parameters are required input, publicKeyPath and privateKeyPath.
You have to provide path of the keys instead of direct key Strings.
Supported values for GREncodingRSA are,
* PKCS1
* OAEP
copied to clipboard
Default is GREncodingRSA.PKCS1
You can find more examples of RSA in the Example Tab
In the examples only base64 encryption and decryption are shown. Similarly you can do for Base16.
Signature Verification #
We only support SHA-256 RSA Signing and verification.
RSA Signing and Verification
For Signing you can use,
Base16 Signing Function
Future<String> grSign16RSA(
{required String input,
required String publicKeyPath,
required String privateKeyPath});
copied to clipboard
This function returns a hex or base16 string
Base64 Signing Function
Future<String> grSign64RSA(
{required String input,
required String publicKeyPath,
required String privateKeyPath});
copied to clipboard
This function returns a base64 string
For Verification you can use,
Base16 Decryption Function
Future<bool> grVerify16RSA(
{required String input,
required String signatureBase16,
required String publicKeyPath,
required String privateKeyPath});
copied to clipboard
The input should be hex or base16 String and returns a boolean value, which is true for successful verification
Base64 Decryption Function
Future<bool> grVerify64RSA(
{required String input,
required String signatureBase64,
required String publicKeyPath,
required String privateKeyPath});
copied to clipboard
The input should be base64 String and returns a boolean value, which is true for successful verification
You can find more examples of Signature Verification in the Example Tab
In the examples only base64 signing and verification are shown. Similarly you can do for Base16.
Additional information #
We are enhancing this library. More features to be added in future.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.