Cryptography Extensions - adyle5/ExtensionsDotNet GitHub Wiki
ComputeHash256Ext
Description
Computes the SHA256 hash value for the string.
Parameters
None
Usage
string x = "test";
byte[] hash = x.ComputeHash256Ext();
ComputeHash512Ext
Description
Computes the SHA512 hash value for the string.
Parameters
None
Usage
string x = "test";
byte[] hash = x.ComputeHash512Ext();
ComputeHash512Ext
Description
Computes the MD5 hash value for the string.
Parameters
None
Usage
string x = "test";
byte[] hash = x.ComputeHashMD5Ext();
GenerateRandomBytesExt
Description
Fills the extended byte array with cryptographically strong random bytes.
Bytes filled can be zero.
Parameters
None
Usage
byte[] bytes = new byte[64];
byte[] randomBytes = bytes.GenerateRandomBytesExt();
GenerateRandomNonZeroBytesExt
Description
Fills the extended byte array with cryptographically strong random bytes.
Bytes will be non-zero.
Parameters
None
Usage
byte[] bytes = new byte[64];
byte[] randomBytes = bytes.GenerateRandomNonZeroBytesExt();
ToTripleDesEncryptedBytesExt
Description
Symmetic encryption of a string using TripleDES.
Returns a tuple that includes the EncryptedBytes, Key, IV.
All three objects in the tuple are byte arrays.
The key and initialization vector are needed to decrypt the byte array back into a string.
Parameters
None
Usage
string text = "This is a test";
var (EncryptedBytes, Key, IV) = text.ToTripleDesEncryptedBytesExt();
ToTripleDesDecryptedStringExt
Description
Symmetic decryption of a byte array back to a string using using TripleDES and the provided key and initialization vector.
The key and initialization vector (IV) were generated when the string was originally encrypted and needed to be stored for decryption.
Parameters
key (byte[])
iv (byte[])
Usage
//var (EncryptedBytes, Key, IV) = text.ToTripleDesEncryptedBytesExt();
string decrypted = EncryptedBytes.ToTripleDesDecryptedStringExt(Key, IV);