C# Класс Westwind.Utilities.Encryption

Class that provides a number of encryption utilities
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
EncryptionKey string

Открытые методы

Метод Описание
BinHexToBinary ( string hex ) : byte[]

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

BinaryToBinHex ( byte data ) : string

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

ComputeHash ( byte byteData, string hashAlgorithm, byte saltBytes, bool useBinHex = false ) : string

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.

ComputeHash ( string plainText, string hashAlgorithm, byte saltBytes, bool useBinHex = false ) : string

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.

ComputeHash ( string plainText, string hashAlgorithm, string salt, bool useBinHex = false ) : string

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.

DecryptBytes ( byte decryptBuffer, byte encryptionKey ) : byte[]

Decrypts a byte buffer with a byte based encryption key

DecryptBytes ( byte decryptBuffer, string encryptionKey ) : byte[]

Decrypts a Byte array from DES with an Encryption Key.

DecryptBytes ( string decryptString, string encryptionKey, bool useBinHex = false ) : byte[]

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

DecryptString ( string decryptString, byte encryptionKey, bool useBinHex = false ) : string

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

DecryptString ( string decryptString, string encryptionKey, bool useBinHex = false ) : string

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

EncryptBytes ( byte inputBytes, byte encryptionKey ) : byte[]

Encrypts a byte buffer with a byte encryption key

EncryptBytes ( byte inputBytes, string encryptionKey ) : byte[]

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

EncryptBytes ( string inputString, string encryptionKey ) : byte[]

Encrypts a string into bytes using DES encryption with a Passkey.

EncryptString ( string inputString, byte encryptionKey, bool useBinHex = false ) : string

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.

EncryptString ( string inputString, string encryptionKey, bool useBinHex = false ) : string

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

GZipFile ( string Filename, string OutputFile ) : bool

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

GZipMemory ( byte buffer ) : byte[]

GZip encodes a memory buffer to a compressed memory buffer

GZipMemory ( string Input ) : byte[]

Encodes a string to a gzip compressed memory buffer

GZipMemory ( string Filename, bool IsFile ) : byte[]

Encodes a file to a gzip memory buffer

GetChecksumFromBytes ( byte fileData, string mode ) : string

Create a SHA256 or MD5 checksum from a bunch of bytes

GetChecksumFromFile ( string file, string mode, bool useBinHex = false ) : string

Creates an SHA256 or MD5 checksum of a file

ProtectBytes ( byte encryptBytes, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

ProtectBytes ( byte encryptBytes, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

ProtectString ( string encryptString, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

ProtectString ( string encryptString, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

UnprotectBytes ( byte encryptBytes, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

UnprotectBytes ( byte encryptBytes, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

UnprotectString ( string encryptString, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

UnprotectString ( string encryptString, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string

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

DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES

Приватные методы

Метод Описание
ParseHexChar ( char c ) : int

Описание методов

BinHexToBinary() публичный статический Метод

Turns a BinHex string that contains raw byte values into a byte array
public static BinHexToBinary ( string hex ) : byte[]
hex string BinHex string (011a031f) just two byte hex digits strung together)
Результат byte[]

BinaryToBinHex() публичный статический Метод

Converts a byte array into a BinHex string. Example: 01552233 where the numbers are packed byte values.
public static BinaryToBinHex ( byte data ) : string
data byte Raw data to send
Результат string

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 ComputeHash ( byte byteData, string hashAlgorithm, byte saltBytes, bool useBinHex = false ) : string
byteData byte /// Plaintext value to be hashed. ///
hashAlgorithm string /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1", /// "SHA256", "SHA384", "SHA512", "HMACMD5", "HMACSHA1", "HMACSHA256", /// "HMACSHA512" (if any other value is specified MD5 will be used). /// /// HMAC algorithms uses Hash-based Message Authentication Code. /// The HMAC process mixes a secret key with the message data, hashes /// the result with the hash function, mixes that hash value with /// the secret key again, and then applies the hash function /// a second time. HMAC hashes are fixed lenght and generally /// much longer than non-HMAC hashes of the same type. /// /// https://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha256(v=vs.110).aspx /// /// This value is case-insensitive. ///
saltBytes byte /// Optional but recommended salt bytes to apply to the hash. If not passed the /// raw encoding is used. If salt is nullthe raw algorithm is used (useful for /// file hashes etc.) HMAC versions REQUIRE that salt is passed. ///
useBinHex bool if true returns the data as BinHex byte pair string. Otherwise Base64 is returned.
Результат string

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 ComputeHash ( string plainText, string hashAlgorithm, byte saltBytes, bool useBinHex = false ) : string
plainText string /// Plaintext value to be hashed. ///
hashAlgorithm string /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1", /// "SHA256", "SHA384", "SHA512", "HMACMD5", "HMACSHA1", "HMACSHA256", /// "HMACSHA512" (if any other value is specified MD5 will be used). /// /// HMAC algorithms uses Hash-based Message Authentication Code. /// The HMAC process mixes a secret key with the message data, hashes /// the result with the hash function, mixes that hash value with /// the secret key again, and then applies the hash function /// a second time. HMAC hashes are fixed lenght and generally /// much longer than non-HMAC hashes of the same type. /// /// https://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha256(v=vs.110).aspx /// /// This value is case-insensitive. ///
saltBytes byte
useBinHex bool if true returns the data as BinHex byte pair string. Otherwise Base64 is returned.
Результат string

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 ComputeHash ( string plainText, string hashAlgorithm, string salt, bool useBinHex = false ) : string
plainText string /// Plaintext value to be hashed. ///
hashAlgorithm string /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1", /// "SHA256", "SHA384", "SHA512", "HMACMD5", "HMACSHA1", "HMACSHA256", /// "HMACSHA512" (if any other value is specified MD5 will be used). /// /// HMAC algorithms uses Hash-based Message Authentication Code. /// The HMAC process mixes a secret key with the message data, hashes /// the result with the hash function, mixes that hash value with /// the secret key again, and then applies the hash function /// a second time. HMAC hashes are fixed lenght and generally /// much longer than non-HMAC hashes of the same type. /// /// https://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha256(v=vs.110).aspx /// /// This value is case-insensitive. ///
salt string /// Optional but recommended salt string to apply to the hash. If not passed the /// raw encoding is used. If salt is nullthe raw algorithm is used (useful for /// file hashes etc.) HMAC versions REQUIRE that salt is passed. ///
useBinHex bool if true returns the data as BinHex byte pair string. Otherwise Base64 is returned.
Результат string

DecryptBytes() публичный статический Метод

Decrypts a byte buffer with a byte based encryption key
public static DecryptBytes ( byte decryptBuffer, byte encryptionKey ) : byte[]
decryptBuffer byte
encryptionKey byte
Результат byte[]

DecryptBytes() публичный статический Метод

Decrypts a Byte array from DES with an Encryption Key.
public static DecryptBytes ( byte decryptBuffer, string encryptionKey ) : byte[]
decryptBuffer byte
encryptionKey string
Результат byte[]

DecryptBytes() публичный статический Метод

Decrypts a string using DES encryption and a pass key that was used for encryption and returns a byte buffer.
public static DecryptBytes ( string decryptString, string encryptionKey, bool useBinHex = false ) : byte[]
decryptString string
encryptionKey string
useBinHex bool Returns data in useBinHex format (12afb1c3f1). Otherwise base64 is returned.
Результат byte[]

DecryptString() публичный статический Метод

Decrypts a string using DES encryption and a pass key that was used for encryption. Class wwEncrypt
public static DecryptString ( string decryptString, byte encryptionKey, bool useBinHex = false ) : string
decryptString string
encryptionKey byte
useBinHex bool Returns data in useBinHex format (12afb1c3f1). Otherwise base64 is returned
Результат string

DecryptString() публичный статический Метод

Decrypts a string using DES encryption and a pass key that was used for encryption. Class wwEncrypt
public static DecryptString ( string decryptString, string encryptionKey, bool useBinHex = false ) : string
decryptString string
encryptionKey string
useBinHex bool Returns data in useBinHex format (12afb1c3f1). Otherwise base64 is returned.
Результат string

EncryptBytes() публичный статический Метод

Encrypts a byte buffer with a byte encryption key
public static EncryptBytes ( byte inputBytes, byte encryptionKey ) : byte[]
inputBytes byte
encryptionKey byte
Результат byte[]

EncryptBytes() публичный статический Метод

Encodes a stream of bytes using DES encryption with a pass key. Lowest level method that handles all work.
public static EncryptBytes ( byte inputBytes, string encryptionKey ) : byte[]
inputBytes byte
encryptionKey string
Результат byte[]

EncryptBytes() публичный статический Метод

Encrypts a string into bytes using DES encryption with a Passkey.
public static EncryptBytes ( string inputString, string encryptionKey ) : byte[]
inputString string
encryptionKey string
Результат byte[]

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 EncryptString ( string inputString, byte encryptionKey, bool useBinHex = false ) : string
inputString string
encryptionKey byte
useBinHex bool if true returns bin hex rather than base64
Результат string

EncryptString() публичный статический Метод

Encrypts a string using Triple DES encryption with a two way encryption key.String is returned as Base64 encoded value rather than binary.
public static EncryptString ( string inputString, string encryptionKey, bool useBinHex = false ) : string
inputString string
encryptionKey string
useBinHex bool
Результат string

GZipFile() публичный статический Метод

Encodes one file to another file that is gzip compressed. File is overwritten if it exists and not locked.
public static GZipFile ( string Filename, string OutputFile ) : bool
Filename string
OutputFile string
Результат bool

GZipMemory() публичный статический Метод

GZip encodes a memory buffer to a compressed memory buffer
public static GZipMemory ( byte buffer ) : byte[]
buffer byte
Результат byte[]

GZipMemory() публичный статический Метод

Encodes a string to a gzip compressed memory buffer
public static GZipMemory ( string Input ) : byte[]
Input string
Результат byte[]

GZipMemory() публичный статический Метод

Encodes a file to a gzip memory buffer
public static GZipMemory ( string Filename, bool IsFile ) : byte[]
Filename string
IsFile bool
Результат byte[]

GetChecksumFromBytes() публичный статический Метод

Create a SHA256 or MD5 checksum from a bunch of bytes
public static GetChecksumFromBytes ( byte fileData, string mode ) : string
fileData byte
mode string SHA256,SHA512,MD5
Результат string

GetChecksumFromFile() публичный статический Метод

Creates an SHA256 or MD5 checksum of a file
public static GetChecksumFromFile ( string file, string mode, bool useBinHex = false ) : string
file string
mode string SHA256,SHA512,MD5
useBinHex bool
Результат string

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static ProtectBytes ( byte encryptBytes, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]
encryptBytes byte
key byte
scope DataProtectionScope
Результат byte[]

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static ProtectBytes ( byte encryptBytes, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]
encryptBytes byte
key string
scope DataProtectionScope
Результат byte[]

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static ProtectString ( string encryptString, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string
encryptString string
key byte
scope DataProtectionScope
useBinHex bool returns bin hex data when set (010A0D10AF)
Результат string

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static ProtectString ( string encryptString, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string
encryptString string
key string
scope DataProtectionScope
useBinHex bool returns bin hex data when set (010A0D10AF)
Результат string

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static UnprotectBytes ( byte encryptBytes, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]
encryptBytes byte
key byte
scope DataProtectionScope
Результат byte[]

UnprotectBytes() публичный статический Метод

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static UnprotectBytes ( byte encryptBytes, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine ) : byte[]
encryptBytes byte
key string
scope DataProtectionScope
Результат byte[]

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static UnprotectString ( string encryptString, byte key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string
encryptString string
key byte
scope DataProtectionScope
useBinHex bool returns bin hex data when set (010A0D10AF)
Результат string

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
DO NOT USE FOR DATA THAT WILL CROSS MACHINE BOUNDARIES
public static UnprotectString ( string encryptString, string key, DataProtectionScope scope = DataProtectionScope.LocalMachine, bool useBinHex = false ) : string
encryptString string
key string
scope DataProtectionScope
useBinHex bool returns bin hex data when set (010A0D10AF)
Результат string

Описание свойств

EncryptionKey публичное статическое свойство

Replace this value with some unique key of your own Best set this in your App start up in a Static constructor
public static string EncryptionKey
Результат string