Helper class with crypto functions.
Members | Descriptions |
---|---|
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. |
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.
keyType
Optional key type. (sha256x2, R1)
key pair
public static byte[]
GetPrivateKeyBytesWithoutCheckSum
(string privateKey)
Get private key bytes without is checksum.
privateKey
private key
byte array
public static string
PubKeyBytesToString
(byte[] keyBytes, string keyType, string prefix)
Convert byte array to encoded public key string.
keyBytes
public key byteskeyType
Optional key type. (sha256x2, R1, K1)prefix
Optional prefix to public key
encoded public key
public static string
PrivKeyBytesToString
(byte[] keyBytes, string keyType, string prefix)
Convert byte array to encoded private key string.
keyBytes
public key byteskeyType
Optional key type. (sha256x2, R1, K1)prefix
Optional prefix to public key
encoded private key
public static string
SignBytesToString
(byte[] signBytes, string keyType, string prefix)
Convert byte array to encoded signature string.
signBytes
signature byteskeyType
Optional key type. (sha256x2, R1, K1)prefix
Optional prefix to public key
encoded signature
public static byte[]
PubKeyStringToBytes
(string key, string prefix)
Convert encoded public key to byte array.
key
encoded public keyprefix
Optional prefix on key
public key bytes
public static byte[]
PrivKeyStringToBytes
(string key)
Convert encoded public key to byte array.
key
encoded public keyprefix
Optional prefix on key
public key bytes
public static byte[]
SignStringToBytes
(string sign)
Convert encoded signature to byte array.
sign
encoded signature
signature bytes
public static byte[]
StringToKey
(string key, int size, string keyType)
Convert Pub/Priv key or signature to byte array.
key
generic keysize
Key sizekeyType
Optional key type. (sha256x2, R1, K1)
key bytes
public static string
KeyToString
(byte[] key, string keyType, string prefix)
Convert key byte array to encoded generic key.
key
key byte arraykeyType
Key type. (sha256x2, R1, K1)prefix
Optional prefix
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
keyBytes
The key used to encrypt the data.plainText
The text to be encrypted.
The encrypted text.
public static string
AesDecrypt
(byte[] keyBytes, byte[] cipherText)
It decrypts the ciphertext using the keyBytes.
keyBytes
The key used to encrypt the data.cipherText
The encrypted text
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.
plainText
The text to be encrypted.Key
The key used to encrypt the data.IV
The 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.
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.
cipherText
The encrypted string.Key
The key used to encrypt the data.IV
The 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.
The decrypted string.