Class Encryption

Class that provides a number of encryption utilities.

System.Object
  Westwind.Utilities.Encryption
public static class Encryption : object

Remarks

For best compatibility across platforms of the Encrypt/Decrypt methods use overloads that use the key as a byte[24] value rather than string or other sized buffers.

Class Members

MemberDescription

EncryptionKey

Replace this value with some unique key of your own Best set this in your App start up in a Static constructor

EncryptionKeySize

Global configuration propery that can be overridden to set the key size used for Encrypt/Decript operations. Choose between 16 bytes (not recommended except for backwards compatibility) or 24 bytes (works both in NET Full and NET Core)

BinaryToBinHex

Converts a byte array into a BinHex string. Example: 01552233 where the numbers are packed byte values.

public static string BinaryToBinHex(Byte[] data)

BinHexToBinary

Turns a BinHex string that contains raw byte values into a byte array

public static Byte[] BinHexToBinary(string hex)

ComputeHash

Generates a hash for the given plain text value and returns a base64-encoded result. Before the hash is computed, a random salt is generated and appended to the plain text. This salt is stored at the end of the hash value, so it can be used later for hash verification.

public static string ComputeHash(string plainText,     string hashAlgorithm,     Byte[] saltBytes,     bool useBinHex)

public static string ComputeHash(string plainText,     string hashAlgorithm,     string salt,     bool useBinHex)

public static string ComputeHash(Byte[] byteData,     string hashAlgorithm,     Byte[] saltBytes,     bool useBinHex)

DecryptBytes

Decrypts a Byte array from DES with an Encryption Key.

public static Byte[] DecryptBytes(Byte[] decryptBuffer,     string encryptionKey)

public static Byte[] DecryptBytes(Byte[] decryptBuffer,     SecureString encryptionKey)

public static Byte[] DecryptBytes(Byte[] decryptBuffer,     Byte[] encryptionKey,     CipherMode cipherMode)

public static Byte[] DecryptBytes(string decryptString,     string encryptionKey,     bool useBinHex)

public static Byte[] DecryptBytes(string decryptString,     SecureString encryptionKey,     bool useBinHex)

DecryptString

Decrypts a string using DES encryption and a pass key that was used for encryption.

public static string DecryptString(string decryptString,     string encryptionKey,     bool useBinHex)

public static string DecryptString(string decryptString,     SecureString encryptionKey,     bool useBinHex)

public static string DecryptString(string decryptString,     Byte[] encryptionKey,     bool useBinHex)

EncryptBytes

Encodes a stream of bytes using DES encryption with a pass key. Lowest level method that handles all work.

public static Byte[] EncryptBytes(Byte[] inputBytes,     string encryptionKey)

public static Byte[] EncryptBytes(Byte[] inputBytes,     SecureString encryptionKey)

public static Byte[] EncryptBytes(Byte[] inputBytes,     Byte[] encryptionKey,     CipherMode cipherMode)

public static Byte[] EncryptBytes(string inputString,     string encryptionKey)

EncryptString

Encrypts a string using Triple DES encryption with a two way encryption key.String is returned as Base64 or BinHex encoded value rather than binary.

public static string EncryptString(string inputString,     Byte[] encryptionKey,     bool useBinHex)

public static string EncryptString(string inputString,     string encryptionKey,     bool useBinHex)

public static string EncryptString(string inputString,     SecureString encryptionKey,     bool useBinHex)

GetChecksumFromBytes

Create a SHA256 or MD5 checksum from a bunch of bytes

public static string GetChecksumFromBytes(Byte[] fileData,     string mode)

GetChecksumFromFile

Creates an SHA256 or MD5 checksum of a file

public static string GetChecksumFromFile(string file,     string mode)

GZipFile

Encodes one file to another file that is gzip compressed. File is overwritten if it exists and not locked.

public static bool GZipFile(string Filename,     string OutputFile)

GZipMemory

GZip encodes a memory buffer to a compressed memory buffer

public static Byte[] GZipMemory(Byte[] buffer)

public static Byte[] GZipMemory(string Input)

public static Byte[] GZipMemory(string Filename,     bool IsFile)

ProtectBytes

Encrypt bytes using the Data Protection API on Windows. This API uses internal keys to encrypt data which is valid for decryption only on the same machine.

This is an idea storage mechanism for application registraions, service passwords and other semi-transient data that is specific to the software used on the current machine

public static Byte[] ProtectBytes(Byte[] encryptBytes,     Byte[] key,     DataProtectionScope scope)

public static Byte[] ProtectBytes(Byte[] encryptBytes,     string key,     DataProtectionScope scope)

ProtectString

Encrypt bytes using the Data Protection API on Windows. This API uses internal keys to encrypt data which is valid for decryption only on the same machine.

This is an idea storage mechanism for application registraions, service passwords and other semi-transient data that is specific to the software used on the current machine

public static string ProtectString(string encryptString,     string key,     DataProtectionScope scope,     bool useBinHex)

public static string ProtectString(string encryptString,     Byte[] key,     DataProtectionScope scope,     bool useBinHex)

UnprotectBytes

Decrypts bytes using the Data Protection API on Windows. This API uses internal keys to encrypt data which is valid for decryption only on the same machine.

This is an idea storage mechanism for application registraions, service passwords and other semi-transient data that is specific to the software used on the current machine

public static Byte[] UnprotectBytes(Byte[] encryptBytes,     Byte[] key,     DataProtectionScope scope)

public static Byte[] UnprotectBytes(Byte[] encryptBytes,     string key,     DataProtectionScope scope)

UnprotectString

Encrypt bytes using the Data Protection API on Windows. This API uses internal keys to encrypt data which is valid for decryption only on the same machine.

This is an idea storage mechanism for application registraions, service passwords and other semi-transient data that is specific to the software used on the current machine

public static string UnprotectString(string encryptString,     string key,     DataProtectionScope scope,     bool useBinHex)

public static string UnprotectString(string encryptString,     Byte[] key,     DataProtectionScope scope,     bool useBinHex)

Requirements

Namespace: Westwind.Utilities
Assembly: westwind.utilities.dll

© West Wind Technologies, 2019 • Updated: 06/23/19
Comment or report problem with topic