CryptoHelper
Helper class with crypto functions.
Summary
class KeyPair
KeyPair with a private and public key.
public static KeyPair GenerateKeyPair(string keyType)
Generate a new key pair based on a key type.
public static byte[] GetPrivateKeyBytesWithoutCheckSum(string privateKey)
Get private key bytes without is checksum.
public static string PubKeyBytesToString(byte[] keyBytes, string keyType, string prefix)
Convert byte array to encoded public key string.
public static string PrivKeyBytesToString(byte[] keyBytes, string keyType, string prefix)
Convert byte array to encoded private key string.
public static string SignBytesToString(byte[] signBytes, string keyType, string prefix)
Convert byte array to encoded signature string.
public static byte[] PubKeyStringToBytes(string key, string prefix)
Convert encoded public key to byte array.
public static byte[] PrivKeyStringToBytes(string key)
Convert encoded public key to byte array.
public static byte[] SignStringToBytes(string sign)
Convert encoded signature to byte array.
public static byte[] StringToKey(string key, int size, string keyType)
Convert Pub/Priv key or signature to byte array.
public static string KeyToString(byte[] key, string keyType, string prefix)
Convert key byte array to encoded generic key.
public static byte[] AesEncrypt(byte[] keyBytes, string plainText)
It takes a 32 byte key and a 16 byte IV, and uses them to encrypt a string
public static string AesDecrypt(byte[] keyBytes, byte[] cipherText)
It decrypts the ciphertext using the keyBytes.
public static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
It takes a string, a key, and an IV, and returns an encrypted byte array.
public static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
It takes a byte array of ciphertext, a byte array of key, and a byte array of IV, and returns a string of plaintext.
Members
class KeyPair
KeyPair with a private and public key.
public static KeyPair GenerateKeyPair(string keyType)
Generate a new key pair based on a key type.
Parameters
keyTypeOptional key type. (sha256x2, R1)
Returns
key pair
public static byte[] GetPrivateKeyBytesWithoutCheckSum(string privateKey)
Get private key bytes without is checksum.
Parameters
privateKeyprivate key
Returns
byte array
public static string PubKeyBytesToString(byte[] keyBytes, string keyType, string prefix)
Convert byte array to encoded public key string.
Parameters
keyBytespublic key byteskeyTypeOptional key type. (sha256x2, R1, K1)prefixOptional prefix to public key
Returns
encoded public key
public static string PrivKeyBytesToString(byte[] keyBytes, string keyType, string prefix)
Convert byte array to encoded private key string.
Parameters
keyBytespublic key byteskeyTypeOptional key type. (sha256x2, R1, K1)prefixOptional prefix to public key
Returns
encoded private key
public static string SignBytesToString(byte[] signBytes, string keyType, string prefix)
Convert byte array to encoded signature string.
Parameters
signBytessignature byteskeyTypeOptional key type. (sha256x2, R1, K1)prefixOptional prefix to public key
Returns
encoded signature
public static byte[] PubKeyStringToBytes(string key, string prefix)
Convert encoded public key to byte array.
Parameters
keyencoded public keyprefixOptional prefix on key
Returns
public key bytes
public static byte[] PrivKeyStringToBytes(string key)
Convert encoded public key to byte array.
Parameters
keyencoded public keyprefixOptional prefix on key
Returns
public key bytes
public static byte[] SignStringToBytes(string sign)
Convert encoded signature to byte array.
Parameters
signencoded signature
Returns
signature bytes
public static byte[] StringToKey(string key, int size, string keyType)
Convert Pub/Priv key or signature to byte array.
Parameters
keygeneric keysizeKey sizekeyTypeOptional key type. (sha256x2, R1, K1)
Returns
key bytes
public static string KeyToString(byte[] key, string keyType, string prefix)
Convert key byte array to encoded generic key.
Parameters
keykey byte arraykeyTypeKey type. (sha256x2, R1, K1)prefixOptional prefix
Returns
public static byte[] AesEncrypt(byte[] keyBytes, string plainText)
It takes a 32 byte key and a 16 byte IV, and uses them to encrypt a string
Parameters
keyBytesThe key used to encrypt the data.plainTextThe text to be encrypted.
Returns
The encrypted text.
public static string AesDecrypt(byte[] keyBytes, byte[] cipherText)
It decrypts the ciphertext using the keyBytes.
Parameters
keyBytesThe key used to encrypt the data.cipherTextThe encrypted text
Returns
The decrypted string.
public static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
It takes a string, a key, and an IV, and returns an encrypted byte array.
Parameters
plainTextThe text to be encrypted.KeyThe key used to encrypt the data.IVThe initialization vector is a random number that is used to encrypt the first block of text in the data. This number is then used in the decryption of the data.
Returns
The encrypted bytes from the memory stream.
public static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
It takes a byte array of ciphertext, a byte array of key, and a byte array of IV, and returns a string of plaintext.
Parameters
cipherTextThe encrypted string.KeyThe key used to encrypt the data.IVThe initialization vector. This is a random string of bytes that is used to initialize the encryption algorithm. It is used to ensure that the same plaintext will not always produce the same ciphertext.
Returns
The decrypted string.
Last updated