CryptoHelper

Helper class with crypto functions.

Summary

MembersDescriptions

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

  • keyType Optional key type. (sha256x2, R1)

Returns

key pair

public static byte[] GetPrivateKeyBytesWithoutCheckSum(string privateKey)

Get private key bytes without is checksum.

Parameters

  • privateKey private key

Returns

byte array

public static string PubKeyBytesToString(byte[] keyBytes, string keyType, string prefix)

Convert byte array to encoded public key string.

Parameters

  • keyBytes public key bytes

  • keyType Optional key type. (sha256x2, R1, K1)

  • prefix Optional 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

  • keyBytes public key bytes

  • keyType Optional key type. (sha256x2, R1, K1)

  • prefix Optional 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

  • signBytes signature bytes

  • keyType Optional key type. (sha256x2, R1, K1)

  • prefix Optional prefix to public key

Returns

encoded signature

public static byte[] PubKeyStringToBytes(string key, string prefix)

Convert encoded public key to byte array.

Parameters

  • key encoded public key

  • prefix Optional prefix on key

Returns

public key bytes

public static byte[] PrivKeyStringToBytes(string key)

Convert encoded public key to byte array.

Parameters

  • key encoded public key

  • prefix Optional prefix on key

Returns

public key bytes

public static byte[] SignStringToBytes(string sign)

Convert encoded signature to byte array.

Parameters

  • sign encoded signature

Returns

signature bytes

public static byte[] StringToKey(string key, int size, string keyType)

Convert Pub/Priv key or signature to byte array.

Parameters

  • key generic key

  • size Key size

  • keyType Optional 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

  • key key byte array

  • keyType Key type. (sha256x2, R1, K1)

  • prefix Optional 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

  • keyBytes The key used to encrypt the data.

  • plainText The text to be encrypted.

Returns

The encrypted text.

public static string AesDecrypt(byte[] keyBytes, byte[] cipherText)

It decrypts the ciphertext using the keyBytes.

Parameters

  • keyBytes The key used to encrypt the data.

  • cipherText The 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

  • 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.

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

  • 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.

Returns

The decrypted string.

Last updated