C# 클래스 Westwind.Utilities.Encryption

Class that provides a number of encryption utilities
파일 보기 프로젝트 열기: RickStrahl/WestwindToolkit

공개 프로퍼티들

프로퍼티 타입 설명
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