IGLib  1.6.0
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
IG.Crypto.UtilCrypto Class Reference

Basic Cryptographic utilities. More...

+ Collaboration diagram for IG.Crypto.UtilCrypto:

Static Public Member Functions

static PasswordAlgorithmType[] GetPasswordAlgorithmTypes ()
 Returns all password algorithm types contained in the enumeration PasswordAlgorithmType More...
 
static PasswordAlgorithmType GetPasswordAlgorithmType (string typeString)
 Returns a PasswordAlgorithmType value corresponding to the specified string representation. More...
 
static PasswordAlgorithmType GetPasswordAlgorithmType (PasswordAlgorithmBase algorithmObject)
 Returns the password generation algorithm type, i.e. an enumeration of type PasswordAlgorithmType, for the specified password generation algorithm object. More...
 
static string PasswordAlgorithmTypeToString (PasswordAlgorithmType passwordAlgorithmType)
 Returns standard string representation of the specified password generation algoithm. More...
 
static
IG.Crypto.PasswordAlgorithmBase 
GetPasswordAlgorithm (PasswordAlgorithmType algorithmType)
 Returns the appropriate password generation algorithm according to the specified algorithm type, or null if the type is not recognized or the method is not implemented for that type. More...
 
static bool IsCorrectPasswordAlgorithm (DeriveBytes algorithm, PasswordAlgorithmType algorithmType)
 Returns true if the specified password generation algorithm corresponds the type specification, false otherwise. More...
 
static string CreateRandomPassword (int PasswordLength, string allowedChars=null)
 Creates and returns a random password consisting of only allowed characters from the specified string. More...
 
static void GetRandomBytes (byte[] byteArray)
 Fills the specified byte array with a cryptographically strong sequence of random bytes. More...
 
static void GetRandomBytes (ref byte[] byteArray, int numBytes)
 Fills the specified byte array with a specified number of cryptographically strong random bytes. More...
 
static byte[] GetRandomBytes (int numBytes)
 Creates and returns an array of cryptographically strong random bytes of the specified size. More...
 
static int GetHashLengthBytes (HashType hashType)
 Returns length of the hash value, in bytes, for the specified hash algorithm. More...
 
static int GetHashLengthHex (HashType hashType)
 Returns length of the HEXADECIMAL hash string for the specified hash algorithm. More...
 
static HashType[] GetHashTypes ()
 Returns all hashing algorithm types contained in the enumeration HashType More...
 
static HashType GetHashType (string typeString)
 Returns a HashType value corresponding to the specified string representation. More...
 
static HashType GetHashType (HashAlgorithm algorithmObject)
 Returns the hashing algorithm type, i.e. an enumeration of type HashType, for the specified hashing algorithm object. More...
 
static string HashTypeToString (HashType hashType)
 Returns standard string representation of the specified hash type. More...
 
static HashAlgorithm GetHashAlgorithm (HashType hashType)
 Returns the appropriate hash algorithm according to the specified hash type, or null if the type is not recognized or the method is not implemented for that type. More...
 
static bool IsCorrectHashAlgorithm (HashAlgorithm algorithm, HashType algorithmType)
 Returns true if the specified cryptographic hash algorithm corresponds the type specification, false otherwise. More...
 
static void ParseHashFile (string filePath, ref List< string[]> hashList)
 Parses the file containing hash values of one or more files, and adds the parsed pairs {hash, inputFilePath} to the specified list. More...
 
static void ParseHashFileString (string str, ref List< string[]> hashList)
 Parses the string containing hash values of one or more files, and adds the parsed pairs {hash, inputFilePath} to the specified list. More...
 
static byte[] GetHashBytes (byte[] bytesToHash, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash (in form of byte array) of the specified kind of the specified byte array. More...
 
static string GetHashHex (byte[] bytesToHash, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash string of the specified kind of the specified byte array. More...
 
static string GetHashMd5Hex (byte[] bytesToHash)
 Computes and returns the MD5 hash string of the specified array of bytes. More...
 
static string GetHashSha1Hex (byte[] bytesToHash)
 Computes and returns the SHA1 hash string of the specified array of bytes. More...
 
static string GetHashSha256Hex (byte[] bytesToHash)
 Computes and returns the SHA256 hash string of the specified array of bytes. More...
 
static string GetHashSha512Hex (byte[] bytesToHash)
 Computes and returns the SHA512 hash string of the specified array of bytes. More...
 
static bool CheckHashHex (byte[] bytesToCheck, string hashValue, HashType hashAlgorithmType)
 Chechs the specified type of hash value of a byte array. More...
 
static HashType CheckHashSupportedTypesHex (byte[] bytesToCheck, string hashValue)
 Chechs all supported types of hash value of a string. More...
 
static byte[] GetStringHashBytes (string stringToHash, HashType hashType=HashType.Default, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash string of the specified kind of the specified string. More...
 
static string GetStringHashHex (string stringToHash, HashType hashType=HashType.Default, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash string of the specified kind of the specified string. More...
 
static string GetStringHashMd5Hex (string stringToHash)
 Computes and returns the MD5 hash string of the specified string. More...
 
static string GetStringHashSha1Hex (string stringToHash)
 Computes and returns the SHA1 hash string of the specified string. More...
 
static string GetStringHashSha256Hex (string stringToHash)
 Computes and returns the SHA256 hash string of the specified string. More...
 
static string GetStringHashSha512Hex (string stringToHash)
 Computes and returns the SHA512 hash string of the specified string. More...
 
static byte[] GetStringSaltedHashBytes (string stringToHash, HashType hashType, string salt, int numIterations=0, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the salted hash (in form of byte array) of the specified kind of the specified string, with the specified number of repetitions of the salted hashing algoriithm. More...
 
static string GetStringSaltedHash (string stringToHash, HashType hashType, string salt, int numIterations=0, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the salted hash of the specified kind of the specified string, with the specified number of repetitions of the salted hashing algoriithm. More...
 
static string GetStringSaltedHashMd5Hex (string stringToHash, string salt, int numIterations=0)
 Computes and returns the MD5 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm. More...
 
static string GetStringSaltedHashSha1Hex (string stringToHash, string salt, int numIterations=0)
 Computes and returns the SHA1 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm. More...
 
static string GetStringSaltedHashSha256Hex (string stringToHash, string salt, int numIterations=0)
 Computes and returns the SHA-256 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm. More...
 
static string GetStringSaltedHashSha512Hex (string stringToHash, string salt, int numIterations=0)
 Computes and returns the SHA-512 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm. More...
 
static bool CheckStringHashHex (string stringToCheck, string hashValue, HashType hashAlgorithmType)
 Chechs the specified type of hash value of a string. More...
 
static HashType CheckStringHashSupportedTypesHex (string stringToCheck, string hashValue)
 Chechs all supported types of hash value of a string. More...
 
static bool CheckStringHashMd5Hex (string stringToCheck, string hashValue)
 Checks whether the specified MD5 hash value matches the actual hash value of the specified string. More...
 
static bool CheckStringHashSha1Hex (string stringToCheck, string hashValue)
 Checks whether the specified SHA-1 hash value matches the actual hash value of the specified string. More...
 
static bool CheckStringHashSha256Hex (string stringToCheck, string hashValue)
 Checks whether the specified SHA-256 hash value matches the actual hash value of the specified string. More...
 
static bool CheckStringHashSha512Hex (string stringToCheck, string hashValue)
 Checks whether the specified SHA-512 hash value matches the actual hash value of the specified string. More...
 
static byte[] GetFileHashBytes (string filePath, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash (in form of byte array) of specified type of the specified stream. More...
 
static string GetFileHashHex (string filePath, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash string of specified type of the specified stream. More...
 
static string GetFileHashMd5Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the MD5 hash string of the specified stream. More...
 
static string GetFileHashSha1Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA1 hash string of the specified stream. More...
 
static string GetFileHashSha256Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA256 hash string of the specified stream. More...
 
static string GetFileHashSha512Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA512 hash string of the specified stream. More...
 
static byte[] GetHashBytes (Stream stream, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hash (in form of byte array) of specified type of the specified stream. More...
 
static string GetHashHex (Stream stream, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hexadecimal hash string of specified type of the specified stream. More...
 
static string GetHashMd5Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the MD5 hash string of the specified stream. More...
 
static string GetHashSha1Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA1 hash string of the specified stream. More...
 
static string GetHashSha256Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA256 hash string of the specified stream. More...
 
static string GetHashSha512Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA512 hash string of the specified stream. More...
 
static bool CheckFileHashHex (string filePath, string hashValue, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Chechs the specified type of hash value of a file. More...
 
static HashType CheckFileHashSupportedTypesHex (string filePath, string hashValue)
 Chechs all supported types of hash value of a file. More...
 
static bool CheckFileHashMd5Hex (string filePath, string hashValue)
 Checks whether the specified MD5 hash value matches the actual hash value of the specified file. More...
 
static bool CheckFileHashSha1Hex (string filePath, string hashValue)
 Checks whether the specified SHA-1 hash value matches the actual hash value of the specified file. More...
 
static bool CheckFileHashSha256Hex (string filePath, string hashValue)
 Checks whether the specified SHA-256 hash value matches the actual hash value of the specified file. More...
 
static bool CheckFileHashSha512Hex (string filePath, string hashValue)
 Checks whether the specified SHA-512 hash value matches the actual hash value of the specified file. More...
 
static SymmetricAlgorithmType[] GetSymmetricAlgorithmTypes ()
 Returns all symmetric encryption algorithm types contained in the enumeration SymmetricAlgorithmType More...
 
static SymmetricAlgorithmType GetSymmetricAlgorithmType (string typeString)
 Returns the SymmetricAlgorithmType value corresponding to the specified string. More...
 
static SymmetricAlgorithmType GetSymmetricAlgorithmType (SymmetricAlgorithm algorithmObject)
 Returns the symmetric encryption algorithm type, i.e. an enumeration of type SymmetricAlgorithmType, for the specified symmetric encryption algorithm object. More...
 
static string SymmetricAlgorithmTypeToString (SymmetricAlgorithmType algorithmType)
 Returns standard string representation of the specified symmetric encryption algorithm type. More...
 
static SymmetricAlgorithm GetSymmetricEncryptionAlgorithm (SymmetricAlgorithmType algorithmType)
 Returns the appropriate symmetric encryption algorithm according to the specified hash type, or null if the type is not recognized or the method is not implemented for that type. More...
 
static bool IsCorrectSymmetricEncryptionAlgorithm (SymmetricAlgorithm algorithm, SymmetricAlgorithmType algorithmType)
 Returns true if the specified symmetric encryption algorithm corresponds the type specification, false otherwise. More...
 
static byte[] PadToAlgorithmBlocksizeCyclic (byte[] byteArray, int blockSize, bool truncateIfLarger=false)
 For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified initialization array is returned, otherwise the modified array that fits the required block size is returned (i.e. has integer number of blocks). More...
 
static byte[] PadToAlgorithmBlocksizeZero (byte[] byteArray, int blockSize, bool truncateIfLarger=false)
 For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified initialization array is returned, otherwise the modified array that fits the required block size is returned (i.e. has integer number of blocks). More...
 
static byte[] PadToSymmetricAlgorithmBlocksizeCyclic (byte[] byteArray, SymmetricAlgorithm algorithm, bool truncateIfLarger=false)
 For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified array is returned, otherwise the modified array that fits the required block size is returned. The array size must be mltiple of the block size. More...
 
static byte[] PadToSymmetricAlgorithmBlocksizeZero (byte[] byteArray, SymmetricAlgorithm algorithm, bool truncateIfLarger=false)
 For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified array is returned, otherwise the modified array that fits the required block size is returned. The array size must be mltiple of the block size. More...
 
static byte[] GetValidSymmetricAlgorithmKey (byte[] key, SymmetricAlgorithm algorithm)
 For the specified symmetric encryption algorithm, this function takes the specified key and checks if the key is of valid size. If yes then the unmodified key is returned, otherwise the modified key that fits the required size is returned. More...
 
static byte[] GetValidSymmetricAlgorithmIV (byte[] IV, SymmetricAlgorithm algorithm)
 For the specified symmetric encryption algorithm, this function takes the specified initialization vector and checks if the vector is of valid size. If yes then the unmodified IV is returned, otherwise the modified IV that fits the required size is returned. More...
 
static int GetLargestSymmetricAlgorithmKeySize (SymmetricAlgorithm algorithm)
 Returns the largest possible key siye, in bits, for the spcified symmetric encryption algorithm. More...
 
static int GetLargestSymmetricAlgorithmBlockSize (SymmetricAlgorithm algorithm)
 Returns the largest possible block siye, in bits, for the spcified symmetric encryption algorithm. More...
 
static void PrepareSymmetricAllgorithmBasic (byte[] passwordBytes, byte[] passwordSalt, ref byte[] key, ref byte[] IV, SymmetricAlgorithmType algorithmType, ref SymmetricAlgorithm algorithm, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Prepares the symmetric algorithm, initialization vector, and key before encryption or decryption takes place. More...
 
static byte[] EncryptBasic (byte[] data, byte[] passwordBytes, byte[] passwordSalt, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the specified byte array by a symmetric encryption algorithm and returns encrypted bytes. More...
 
static byte[] DecryptBasic (byte[] data, byte[] passwordBytes, byte[] passwordSalt, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Decrypts the specified byte array by a symmetric algorithm and returns decrypted data. More...
 
static string EncryptStringBasic (string stringToEncrypt, byte[] passwordBytes, byte[] passwordSalt, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the specified string, using the specified symmetric algorithm, key, and initialization vector, and returns the ToBase64 string representation of the encrypted bytes. More...
 
static string DecryptStringBasic (string cipherText, byte[] passwordBytes, byte[] passwordSalt, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Derypts the specified string from encryted byte array, using the specified symmetric algorithm, key, and initialization vector. More...
 
static void EncryptFileBasic (string inputFilePath, string outputFilePath, byte[] passwordBytes, byte[] passwordSalt, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, int bufferSize=ConstCrypto.FileBufferSize, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the data from the specified input file by a symmetric encryption algorithm and writes encrypted data to the specified output file. More...
 
static void DecryptFileBasic (string inputFilePath, string outputFilePath, byte[] passwordBytes, byte[] passwordSalt, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, int bufferSize=ConstCrypto.FileBufferSize, PasswordAlgorithmType pwdType=PasswordAlgorithmType.Default, int pwdNumIterations=1000, bool useLargestKey=false, bool useLargestBlock=false)
 Decrypts the data from the specified input file by a symmetric encryption algorithm and writes decrypted data to the specified output file. More...
 
static void PrepareSymmetricAllgorithmPlain (ref byte[] key, ref byte[] IV, SymmetricAlgorithmType algorithmType, ref SymmetricAlgorithm algorithm, bool useLargestKey=false, bool useLargestBlock=false)
 Prepares the symmetric algorithm, initialization vector, and key before encryption or decryption takes place. More...
 
static void EncryptPlain (byte[] data, Stream outputStream, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the specified byte array by a symmetric encryption algorithm and writes encrypted data to the specified output stream that must be open for writing. More...
 
static void DecryptPlain (byte[] data, Stream outputStream, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, bool useLargestKey=false, bool useLargestBlock=false)
 Decrypts the specified byte array by a symmetric algorithm and writes decrypted data to the specified output stream. More...
 
static byte[] EncryptPlain (byte[] data, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the specified byte array by a symmetric encryption algorithm and returns encrypted bytes. More...
 
static byte[] DecryptPlain (byte[] data, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, bool useLargestKey=false, bool useLargestBlock=false)
 Decrypts the specified byte array by a symmetric algorithm and returns decrypted data. More...
 
static string EncryptStringPlain (string stringToEncrypt, byte[] key, byte[] initializationVector, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the specified string, using the specified symmetric algorithm, key, and initialization vector, and returns the Base64 string representation of the encrypted bytes. More...
 
static string DecryptStringPlain (string cipherText, byte[] key, byte[] initializationVector, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, bool useLargestKey=false, bool useLargestBlock=false)
 Derypts the specified string from encryted byte array, using the specified symmetric algorithm, key, and initialization vector. More...
 
static byte[] EncryptStringToBytesPlain (string stringToEncrypt, byte[] key, byte[] initializationVector, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the specified string to a byte array, using the specified symmetric algorithm, key, and initialization vector. More...
 
static string DecryptStringFromBytesPlain (byte[] cipherText, byte[] key, byte[] initializationVector, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.Default, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, bool useLargestKey=false, bool useLargestBlock=false)
 Derypts the specified string from encryted byte array, using the specified symmetric algorithm, key, and initialization vector. More...
 
static void EncryptPlain (Stream inputStream, Stream outputStream, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, int bufferSize=ConstCrypto.FileBufferSize, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the data from the specified input stream by a symmetric encryption algorithm and writes encrypted data to the specified output stream. More...
 
static void DecryptPlain (Stream inputStream, Stream outputStream, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, int bufferSize=ConstCrypto.FileBufferSize, bool useLargestKey=false, bool useLargestBlock=false)
 Decrypts the data from the specified input stream by a symmetric encryption algorithm and writes decrypted data to the specified output stream. More...
 
static void EncryptFilePlain (string inputFilePath, string outputFilePath, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, byte[] saltBytes=null, int bufferSize=ConstCrypto.FileBufferSize, bool useLargestKey=false, bool useLargestBlock=false)
 Encrypts the data from the specified input file by a symmetric encryption algorithm and writes encrypted data to the specified output file. More...
 
static void DecryptFilePlain (string inputFilePath, string outputFilePath, byte[] key, byte[] IV, SymmetricAlgorithmType algorithmType=SymmetricAlgorithmType.None, SymmetricAlgorithm algorithm=null, int numSaltBytes=0, int bufferSize=ConstCrypto.FileBufferSize, bool useLargestKey=false, bool useLargestBlock=false)
 Decrypts the data from the specified input file by a symmetric encryption algorithm and writes decrypted data to the specified output file. More...
 
static AsymmetricAlgorithmType[] GetAsymmetricAlgorithmTypes ()
 Returns all asymmetric encryption algorithm types contained in the enumeration AsymmetricAlgorithmType More...
 
static AsymmetricAlgorithmType GetAsymmetricAlgorithmType (string typeString)
 Returns the AsymmetricAlgorithmType value corresponding to the specified string. More...
 
static AsymmetricAlgorithmType GetAsymmetricAlgorithmType (AsymmetricAlgorithm algorithmObject)
 Returns the asymmetric encryption algorithm type, i.e. an enumeration of type SymmetricAlgorithmType, for the specified asymmetric encryption algorithm object. More...
 
static string AsymmetricAlgorithmTypeToString (AsymmetricAlgorithmType algorithmType)
 Returns standard string representation of the specified asymmetric encryption algorithm type. More...
 
static AsymmetricAlgorithm GetAsymmetricEncryptionAlgorithm (AsymmetricAlgorithmType algorithmType)
 Returns the appropriate asymmetric algorithm according to the specified hash type, or null if the type is not recognized or the method is not implemented for that type. More...
 
static bool IsCorrectAsymmetricEncryptionAlgorithm (AsymmetricAlgorithm algorithm, AsymmetricAlgorithmType algorithmType)
 Returns true if the specified asymmetric encryption algorithm corresponds the type specification, false otherwise. More...
 
static int GetLargestAsymmetricAlgorithmKeySize (AsymmetricAlgorithm algorithm)
 Returns the largest possible key size, in bits, for the spcified symmetric encryption algorithm. More...
 
static byte[] GetValidAsymmetricAlgorithmKey (byte[] key, AsymmetricAlgorithm algorithm, bool useLargestKey=false)
 For the specified asymmetric encryption algorithm, this function takes the specified key and checks if the key is of valid size. If yes then the unmodified key is returned, otherwise the modified key that fits the required size is returned. More...
 
static string IgGetSaltSuffix (int whichSalt)
 Returns the specified standard IGLib salt string. More...
 
static int IgGetNumSaltSuffices ()
 Returns the number of standard IGLib salt strings. More...
 

Properties

static int OutputLevel [get]
 Output level for static methods of the current utility class. More...
 
static object LockStatic [get]
 Locking object for static methods and properties of this class. More...
 
static Encoding StringEncoding [get]
 Gets the character encoding that is used for calculating hashes of strings. More...
 
static RNGCryptoServiceProvider Rng [get]
 Object used to generate random bytes. More...
 

Static Private Member Functions

static PasswordAlgorithmBase GetPasswordAlgorithmNoneSingleton ()
 Returns password algorithm that does not change the password provided as initialization parameters. More...
 
static int SetLargestSymmetricAlgorithmKeySize (SymmetricAlgorithm algorithm)
 On the specified symmetric encryption algorythm, sets the largest possible key size, in bits, for the spcified symmetric encryption algorithm. More...
 
static int SetLargestSymmetricAlgorithmBlockSize (SymmetricAlgorithm algorithm)
 On the specified symmetric encryption algorithm, sets the largest possible block size, in bits, for the spcified symmetric encryption algorithm. More...
 
static int SetLargestAsymmetricAlgorithmKeySize (AsymmetricAlgorithm algorithm)
 On the specified asymmetric encryption algorithm, sets the largest possible key size, in bits, for the corresponding asymmetric encryption algorithm. More...
 

Static Private Attributes

static int _outputLevel = 1
 
static object _lockStatic = null
 
static PasswordAlgorithmType[] _passwordAlgorithmTypes = null
 
static PasswordAlgorithmBase _passwordAlgorithmNone = null
 
static RNGCryptoServiceProvider _rng = null
 
static HashType[] _hashTypes = null
 
static SymmetricAlgorithmType[] _symmetricTypes = null
 
static AsymmetricAlgorithmType[] _asymmetricTypes = null
 
static string[] _igLibLongSaltSuffices
 An array of standard IGLib salt suffices. More...
 

Detailed Description

Basic Cryptographic utilities.

Warnings:

- Functions of this class must be fixed (may not change over time) in order not to break any security instruments.

- Functions can only be renamd (always by refactoring tools that change all calls to functions).

- For IGLib functions (IGLib specific supplements of standards), these should only be used through standard shell applications. In such a way security tools can not be broken, as shell functions are more guaranteed to behave constantly over time.

See also:

- Cryptographic hash function: http://en.wikipedia.org/wiki/Cryptographic_hash_function

- Password verification: http://en.wikipedia.org/wiki/Cryptographic_hash_function#Password_verification

- Storing passwords: http://www.aspheute.com/english/20040105.asp

- How to encrypt user passwords: http://www.jasypt.org/howtoencryptuserpasswords.html

- Salt: https://en.wikipedia.org/wiki/Salt_(cryptography)

- Key stretching: http://en.wikipedia.org/wiki/Key_stretching

$A Igor Apr10 Jun15;

Member Function Documentation

static PasswordAlgorithmType [] IG.Crypto.UtilCrypto.GetPasswordAlgorithmTypes ( )
inlinestatic

Returns all password algorithm types contained in the enumeration PasswordAlgorithmType

References IG.Lib.Util.LockGlobal.

static PasswordAlgorithmType IG.Crypto.UtilCrypto.GetPasswordAlgorithmType ( string  typeString)
inlinestatic
static PasswordAlgorithmType IG.Crypto.UtilCrypto.GetPasswordAlgorithmType ( PasswordAlgorithmBase  algorithmObject)
inlinestatic

Returns the password generation algorithm type, i.e. an enumeration of type PasswordAlgorithmType, for the specified password generation algorithm object.

Parameters
algorithmObjectPassword generaton algorithm object for which type enumeration is returned.
Returns
The type enumeration corresponding to the specified algorithm, or 0 (None) if the algorithm is null or not contained in the enumeration.
static string IG.Crypto.UtilCrypto.PasswordAlgorithmTypeToString ( PasswordAlgorithmType  passwordAlgorithmType)
inlinestatic

Returns standard string representation of the specified password generation algoithm.

Password algorithm type whose string representation is returned.

Referenced by IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmBasic().

static PasswordAlgorithmBase IG.Crypto.UtilCrypto.GetPasswordAlgorithmNoneSingleton ( )
inlinestaticprivate

Returns password algorithm that does not change the password provided as initialization parameters.

The same object is returned by each call.

References IG.Lib.Util.LockGlobal.

static IG.Crypto.PasswordAlgorithmBase IG.Crypto.UtilCrypto.GetPasswordAlgorithm ( PasswordAlgorithmType  algorithmType)
inlinestatic

Returns the appropriate password generation algorithm according to the specified algorithm type, or null if the type is not recognized or the method is not implemented for that type.

Parameters
algorithmTypeSpecification of the password generaion algorithm type.

Referenced by IG.Crypto.CryptoManager.AppKeyGenerationAll(), IG.Script.ScriptAppBase.CryptoFunctionTimeKeyGeneration_OLD_TO_DELETE_LATER(), and IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmBasic().

static bool IG.Crypto.UtilCrypto.IsCorrectPasswordAlgorithm ( DeriveBytes  algorithm,
PasswordAlgorithmType  algorithmType 
)
inlinestatic

Returns true if the specified password generation algorithm corresponds the type specification, false otherwise.

If the specified algorithm is null or the specified type is unknown then false is returned.

Parameters
algorithmTypeSpecification of the password derivation nalgorithm type.
algorithmAlgorithm that is checked for type correctness.
static string IG.Crypto.UtilCrypto.CreateRandomPassword ( int  PasswordLength,
string  allowedChars = null 
)
inlinestatic

Creates and returns a random password consisting of only allowed characters from the specified string.

Cryptographically secure random numbers are used to select characters for the password from the array of allowed characters.

Parameters
PasswordLengthLength of the generated password.
allowedCharsString containing allowed characters of the password.

By default (if parameter is a null or empty string), these are digits and lower- and upper- case English letters.

Returns
A random password of specified length.
static void IG.Crypto.UtilCrypto.GetRandomBytes ( byte[]  byteArray)
inlinestatic

Fills the specified byte array with a cryptographically strong sequence of random bytes.

Parameters
byteArrayByte array that is filled with random bytes.

Referenced by IG.Script.ScriptAppBase.CryptoFunctionTimeKeyGeneration_OLD_TO_DELETE_LATER(), and IG.Crypto.CryptoManager.ResolvePasswordParameters().

static void IG.Crypto.UtilCrypto.GetRandomBytes ( ref byte[]  byteArray,
int  numBytes 
)
inlinestatic

Fills the specified byte array with a specified number of cryptographically strong random bytes.

Byte array is created anew if its size does not equal the specified number of bytes.

Parameters
byteArrayByte array that is filled with random bytes. Reallocated if necessary.
numBytesNumber of bytes to be filled into the array.
static byte [] IG.Crypto.UtilCrypto.GetRandomBytes ( int  numBytes)
inlinestatic

Creates and returns an array of cryptographically strong random bytes of the specified size.

Parameters
numBytesNumber of bytes to be filled into the array.
static int IG.Crypto.UtilCrypto.GetHashLengthBytes ( HashType  hashType)
inlinestatic

Returns length of the hash value, in bytes, for the specified hash algorithm.

-1 is returned if the length is not known.

Parameters
HashAlgorithmTypeType of the hashing algorithm.
static int IG.Crypto.UtilCrypto.GetHashLengthHex ( HashType  hashType)
inlinestatic

Returns length of the HEXADECIMAL hash string for the specified hash algorithm.

-1 is returned if the length is not known.

Parameters
HashAlgorithmTypeType of the hashing algorithm.
static HashType [] IG.Crypto.UtilCrypto.GetHashTypes ( )
inlinestatic

Returns all hashing algorithm types contained in the enumeration HashType

References IG.Lib.Util.LockGlobal.

static HashType IG.Crypto.UtilCrypto.GetHashType ( string  typeString)
inlinestatic

Returns a HashType value corresponding to the specified string representation.

Parameters
typeStringString that represents the hash type.

Referenced by IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE(), and IG.Crypto.CryptoManager.ParseCommandlineParameters().

static HashType IG.Crypto.UtilCrypto.GetHashType ( HashAlgorithm  algorithmObject)
inlinestatic

Returns the hashing algorithm type, i.e. an enumeration of type HashType, for the specified hashing algorithm object.

Parameters
algorithmObjectHashing algorithm object for which type enumeration is returned.
Returns
The type enumeration corresponding to the specified algorithm, or 0 (None) if the algorithm is null or not contained in the enumeration.
static string IG.Crypto.UtilCrypto.HashTypeToString ( HashType  hashType)
inlinestatic

Returns standard string representation of the specified hash type.

Parameters
HashAlgorithmTypeHash type whose string representation is returned.
static HashAlgorithm IG.Crypto.UtilCrypto.GetHashAlgorithm ( HashType  hashType)
inlinestatic

Returns the appropriate hash algorithm according to the specified hash type, or null if the type is not recognized or the method is not implemented for that type.

Parameters
HashAlgorithmTypeSpecification of the hash algorithm type.
static bool IG.Crypto.UtilCrypto.IsCorrectHashAlgorithm ( HashAlgorithm  algorithm,
HashType  algorithmType 
)
inlinestatic

Returns true if the specified cryptographic hash algorithm corresponds the type specification, false otherwise.

If the specified algorithm is null or the specified type is unknown then false is returned.

Parameters
algorithmTypeSpecification of the cryptographic hash algorithm type.
algorithmAlgorithm that is checked for type correctness.
static void IG.Crypto.UtilCrypto.ParseHashFile ( string  filePath,
ref List< string[]>  hashList 
)
inlinestatic

Parses the file containing hash values of one or more files, and adds the parsed pairs {hash, inputFilePath} to the specified list.

File must be in the standard format where each line contains a hash value and the path to the corresponding file separated from hash value by one or more spaces.

List is allocated if necessary. Eventual existent pairs on the list are not affected.

Parameters
inputFilePathPath to the file that is parsed.
hashListList to which which parsed pairs {hash, inputFilePath} are added in form of arrays of 2 strings.

Example contents of the file:

595f44fec1e92a71d3e9e77456ba80d1 filetohashA.txt

71f920fa275127a7b60fa4d4d41432a3 filetohashB.txt

43c191bf6d6c3f263a8cd0efd4a058ab filetohashC.txt

/remarks>

Referenced by IG.Crypto.CryptoManager.AppCheckSum(), IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), and IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE().

static void IG.Crypto.UtilCrypto.ParseHashFileString ( string  str,
ref List< string[]>  hashList 
)
inlinestatic

Parses the string containing hash values of one or more files, and adds the parsed pairs {hash, inputFilePath} to the specified list.

String must be in the standard format where each line contains a hash value and the path to the corresponding file separated from hash value by one or more spaces.

List is allocated if necessary. Eventual existent pairs on the list are not affected.

Parameters
strString that is parsed.
hashListList to which which parsed pairs {hash, inputFilePath} are added in form of arrays of 2 strings.

Example contents of the string:

595f44fec1e92a71d3e9e77456ba80d1 filetohashA.txt

71f920fa275127a7b60fa4d4d41432a3 filetohashB.txt

43c191bf6d6c3f263a8cd0efd4a058ab filetohashC.txt

/remarks>

static byte [] IG.Crypto.UtilCrypto.GetHashBytes ( byte[]  bytesToHash,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash (in form of byte array) of the specified kind of the specified byte array.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
bytesToHashByte array whose hash string is calculated.
HashAlgorithmTypeSpecifies the type of the hashing algorithm to be used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetHashHex ( byte[]  bytesToHash,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash string of the specified kind of the specified byte array.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
bytesToHashByte array whose hash string is calculated.
HashAlgorithmTypeSpecifies the type of the hashing algorithm to be used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.

References IG.Lib.Util.ToHexString().

Referenced by IG.Crypto.CryptoManager.AppCheckSum().

static string IG.Crypto.UtilCrypto.GetHashMd5Hex ( byte[]  bytesToHash)
inlinestatic

Computes and returns the MD5 hash string of the specified array of bytes.

Parameters
bytesToHashByte array whose hash string is calculated.
static string IG.Crypto.UtilCrypto.GetHashSha1Hex ( byte[]  bytesToHash)
inlinestatic

Computes and returns the SHA1 hash string of the specified array of bytes.

Parameters
bytesToHashByte array whose hash string is calculated.
static string IG.Crypto.UtilCrypto.GetHashSha256Hex ( byte[]  bytesToHash)
inlinestatic

Computes and returns the SHA256 hash string of the specified array of bytes.

Parameters
bytesToHashByte array whose hash string is calculated.
static string IG.Crypto.UtilCrypto.GetHashSha512Hex ( byte[]  bytesToHash)
inlinestatic

Computes and returns the SHA512 hash string of the specified array of bytes.

Parameters
bytesToHashByte array whose hash string is calculated.
static bool IG.Crypto.UtilCrypto.CheckHashHex ( byte[]  bytesToCheck,
string  hashValue,
HashType  hashAlgorithmType 
)
inlinestatic

Chechs the specified type of hash value of a byte array.

Returns true if the hash value matches the hash value of the byte array, and false otherwise.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose correctness is checked.
HashAlgorithmTypeType of the hash value that is checked.
Returns
True if the specified hash HashValue actually matches the hash value of the type HashAlgorithmType of the verified string bytesToCheck , or false otherwise.

References IG.Lib.Util.AreHexStringsEqual().

Referenced by IG.Crypto.CryptoManager.AppCheckSum().

static HashType IG.Crypto.UtilCrypto.CheckHashSupportedTypesHex ( byte[]  bytesToCheck,
string  hashValue 
)
inlinestatic

Chechs all supported types of hash value of a string.

Returns the hash type if the hash value matches the hash value of that type of the specified string, or HashType.None if the specified hash value doesn't match the hash value of any supported type of the string.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose match with the specified string is checked.
Returns
Type of the hash value that matches the specified hash value of the specified string, or HashType.None if the specified hash value doesn't match the hash value of any supported type of the specified string.

References IG.Lib.Util.AreHexStringsEqual().

static byte [] IG.Crypto.UtilCrypto.GetStringHashBytes ( string  stringToHash,
HashType  hashType = HashType.Default,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash string of the specified kind of the specified string.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose hash string is calculated.
HashAlgorithmTypeSpecifies the type of the hashing algorithm to be used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetStringHashHex ( string  stringToHash,
HashType  hashType = HashType.Default,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash string of the specified kind of the specified string.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose hash string is calculated.
HashAlgorithmTypeSpecifies the type of the hashing algorithm to be used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.

References IG.Lib.Util.ToHexString().

Referenced by IG.Crypto.CryptoManager.AppCheckSum(), IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), and IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE().

static string IG.Crypto.UtilCrypto.GetStringHashMd5Hex ( string  stringToHash)
inlinestatic

Computes and returns the MD5 hash string of the specified string.

Parameters
stringToHashString whose cryptographic hash is calculated.

Referenced by IG.Forms.HashGeneratorControl.CalculateHashes().

static string IG.Crypto.UtilCrypto.GetStringHashSha1Hex ( string  stringToHash)
inlinestatic

Computes and returns the SHA1 hash string of the specified string.

Parameters
stringToHashString whose cryptographic hash is calculated.

Referenced by IG.Forms.HashGeneratorControl.CalculateHashes().

static string IG.Crypto.UtilCrypto.GetStringHashSha256Hex ( string  stringToHash)
inlinestatic

Computes and returns the SHA256 hash string of the specified string.

Parameters
stringToHashString whose cryptographic hash is calculated.

Referenced by IG.Forms.HashGeneratorControl.CalculateHashes().

static string IG.Crypto.UtilCrypto.GetStringHashSha512Hex ( string  stringToHash)
inlinestatic

Computes and returns the SHA512 hash string of the specified string.

Parameters
stringToHashString whose cryptographic hash is calculated.

Referenced by IG.Forms.HashGeneratorControl.CalculateHashes().

static byte [] IG.Crypto.UtilCrypto.GetStringSaltedHashBytes ( string  stringToHash,
HashType  hashType,
string  salt,
int  numIterations = 0,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the salted hash (in form of byte array) of the specified kind of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose salted hash is to be computed.
HashAlgorithmTypeType of hashing algorithm used.
saltSalt string.
numIterationsOptional number of iterations. If hreater than 0 then hashing algorithm is reapplied to the salted result of the previous computation for the specified number of time.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
Returns
The salted hash of the specified string, with specified hash, and specified number of repetitions of the salted hash calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHash ( string  stringToHash,
HashType  hashType,
string  salt,
int  numIterations = 0,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the salted hash of the specified kind of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose salted hash is to be computed.
HashAlgorithmTypeType of hashing algorithm used.
saltSalt string.
numIterationsOptional number of iterations. If hreater than 0 then hashing algorithm is reapplied to the salted result of the previous computation for the specified number of time.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
Returns
The salted hash of the specified string, with specified hash, and specified number of repetitions of the salted hash calculation.

References IG.Lib.Util.ToHexString().

static string IG.Crypto.UtilCrypto.GetStringSaltedHashMd5Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

Computes and returns the MD5 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose salted hash is to be computed.
saltSalt string.
numIterationsOptional number of iterations. If hreater than 0 then hashing algorithm is reapplied to the salted result of the previous computation for the specified number of time.
Returns
The salted hash of the specified string, with specified hash, and specified number of repetitions of the salted hash calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHashSha1Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

Computes and returns the SHA1 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose salted hash is to be computed.
saltSalt string.
numIterationsOptional number of iterations. If hreater than 0 then hashing algorithm is reapplied to the salted result of the previous computation for the specified number of time.
Returns
The salted hash of the specified string, with specified hash, and specified number of repetitions of the salted hash calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHashSha256Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

Computes and returns the SHA-256 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose salted hash is to be computed.
saltSalt string.
numIterationsOptional number of iterations. If hreater than 0 then hashing algorithm is reapplied to the salted result of the previous computation for the specified number of time.
Returns
The salted hash of the specified string, with specified hash, and specified number of repetitions of the salted hash calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHashSha512Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

Computes and returns the SHA-512 salted hash of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

Exception (InvalidOperationException) is thrown if the specified hash type is not known or implemented.

Parameters
stringToHashString whose salted hash is to be computed.
saltSalt string.
numIterationsOptional number of iterations. If hreater than 0 then hashing algorithm is reapplied to the salted result of the previous computation for the specified number of time.
Returns
The salted hash of the specified string, with specified hash, and specified number of repetitions of the salted hash calculation.
static bool IG.Crypto.UtilCrypto.CheckStringHashHex ( string  stringToCheck,
string  hashValue,
HashType  hashAlgorithmType 
)
inlinestatic

Chechs the specified type of hash value of a string.

Returns true if the hash value matches the hash value of the string, and false otherwise.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose correctness is checked.
HashAlgorithmTypeType of the hash value that is checked.
Returns
True if the specified hash HashValue actually matches the hash value of the type HashAlgorithmType of the verified string bytesToCheck , or false otherwise.

References IG.Lib.Util.AreHexStringsEqual().

Referenced by IG.Crypto.CryptoManager.AppCheckSum(), IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), and IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE().

static HashType IG.Crypto.UtilCrypto.CheckStringHashSupportedTypesHex ( string  stringToCheck,
string  hashValue 
)
inlinestatic

Chechs all supported types of hash value of a string.

Returns the hash type if the hash value matches the hash value of that type of the specified string, or HashType.None if the specified hash value doesn't match the hash value of any supported type of the string.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose match with the specified string is checked.
Returns
Type of the hash value that matches the specified hash value of the specified string, or HashType.None if the specified hash value doesn't match the hash value of any supported type of the specified string.

References IG.Lib.Util.AreHexStringsEqual().

Referenced by IG.Forms.HashGeneratorControl.VerifyHash().

static bool IG.Crypto.UtilCrypto.CheckStringHashMd5Hex ( string  stringToCheck,
string  hashValue 
)
inlinestatic

Checks whether the specified MD5 hash value matches the actual hash value of the specified string.

Returns true if the specified hash value matches the actual hash value of the string, and false otherwise.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified string.
Returns
True if the specified hash value matches the actual value, false otherwise.
static bool IG.Crypto.UtilCrypto.CheckStringHashSha1Hex ( string  stringToCheck,
string  hashValue 
)
inlinestatic

Checks whether the specified SHA-1 hash value matches the actual hash value of the specified string.

Returns true if the specified hash value matches the actual hash value of the string, and false otherwise.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified string.
Returns
True if the specified hash value matches the actual value, false otherwise.
static bool IG.Crypto.UtilCrypto.CheckStringHashSha256Hex ( string  stringToCheck,
string  hashValue 
)
inlinestatic

Checks whether the specified SHA-256 hash value matches the actual hash value of the specified string.

Returns true if the specified hash value matches the actual hash value of the string, and false otherwise.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified string.
Returns
True if the specified hash value matches the actual value, false otherwise.
static bool IG.Crypto.UtilCrypto.CheckStringHashSha512Hex ( string  stringToCheck,
string  hashValue 
)
inlinestatic

Checks whether the specified SHA-512 hash value matches the actual hash value of the specified string.

Returns true if the specified hash value matches the actual hash value of the string, and false otherwise.

Parameters
bytesToCheckString whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified string.
Returns
True if the specified hash value matches the actual value, false otherwise.
static byte [] IG.Crypto.UtilCrypto.GetFileHashBytes ( string  filePath,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash (in form of byte array) of specified type of the specified stream.

Parameters
inputFilePathPath to the file whose contents' cryptographic hash is calculated.
HashAlgorithmTypeSpecifies the type of the hashing algorithm to be used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetFileHashHex ( string  filePath,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash string of specified type of the specified stream.

Parameters
inputFilePathPath to the file whose contents' cryptographic hash is calculated.
HashAlgorithmTypeSpecifies the type of the hashing algorithm to be used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.

Referenced by IG.Crypto.CryptoManager.AppCheckSum(), IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), and IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE().

static string IG.Crypto.UtilCrypto.GetFileHashMd5Hex ( string  filePath,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the MD5 hash string of the specified stream.

Parameters
inputFilePathPath to the file whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.

Referenced by IG.Crypto.CryptoManager.AppGetFileHash(), IG.Forms.HashGeneratorControl.CalculateHashes(), and IG.Script.ScriptAppBase.CryptoFunctionGetFileHash_OLD_TO_DELETE().

static string IG.Crypto.UtilCrypto.GetFileHashSha1Hex ( string  filePath,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the SHA1 hash string of the specified stream.

Parameters
inputFilePathPath to the file whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.

Referenced by IG.Crypto.CryptoManager.AppGetFileHash(), IG.Forms.HashGeneratorControl.CalculateHashes(), and IG.Script.ScriptAppBase.CryptoFunctionGetFileHash_OLD_TO_DELETE().

static string IG.Crypto.UtilCrypto.GetFileHashSha256Hex ( string  filePath,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the SHA256 hash string of the specified stream.

Parameters
inputFilePathPath to the file whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.

Referenced by IG.Crypto.CryptoManager.AppGetFileHash(), IG.Forms.HashGeneratorControl.CalculateHashes(), and IG.Script.ScriptAppBase.CryptoFunctionGetFileHash_OLD_TO_DELETE().

static string IG.Crypto.UtilCrypto.GetFileHashSha512Hex ( string  filePath,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the SHA512 hash string of the specified stream.

Parameters
inputFilePathPath to the file whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by teh method. Its type must correspond the specified type.

Referenced by IG.Crypto.CryptoManager.AppGetFileHash(), IG.Forms.HashGeneratorControl.CalculateHashes(), and IG.Script.ScriptAppBase.CryptoFunctionGetFileHash_OLD_TO_DELETE().

static byte [] IG.Crypto.UtilCrypto.GetHashBytes ( Stream  stream,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hash (in form of byte array) of specified type of the specified stream.

Parameters
streamStream whose contents' cryptographic hash is calculated.
HashAlgorithmTypeType of the hash algorithm used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetHashHex ( Stream  stream,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the hexadecimal hash string of specified type of the specified stream.

Parameters
streamStream whose contents' cryptographic hash is calculated.
HashAlgorithmTypeType of the hash algorithm used.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.

References IG.Lib.Util.ToHexString().

static string IG.Crypto.UtilCrypto.GetHashMd5Hex ( Stream  stream,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the MD5 hash string of the specified stream.

Parameters
streamStream whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetHashSha1Hex ( Stream  stream,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the SHA1 hash string of the specified stream.

Parameters
streamStream whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetHashSha256Hex ( Stream  stream,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the SHA256 hash string of the specified stream.

Parameters
streamStream whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
static string IG.Crypto.UtilCrypto.GetHashSha512Hex ( Stream  stream,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Computes and returns the SHA512 hash string of the specified stream.

Parameters
streamStream whose contents' cryptographic hash is calculated.
cryptoAlgorithmAlgorithm objedt used to perform the job. If not specified then it is created by the method. Its type must correspond the specified type.
static bool IG.Crypto.UtilCrypto.CheckFileHashHex ( string  filePath,
string  hashValue,
HashType  hashType,
HashAlgorithm  cryptoAlgorithm = null 
)
inlinestatic

Chechs the specified type of hash value of a file.

Returns true if the specified hash value matches the hash value of the file, and false otherwise.

Parameters
inputFilePathPath to the file whose hash value is checked.
HashValueSupposed hash value whose correctness is checked.
HashAlgorithmTypeType of the hash value that is checked.
Returns
True if the specified hash HashValue actually matches the hash value of the type HashAlgorithmType of the verified file inputFilePath , or false otherwise.

References IG.Lib.Util.AreHexStringsEqual().

Referenced by IG.Crypto.CryptoManager.AppCheckSum(), IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), and IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE().

static HashType IG.Crypto.UtilCrypto.CheckFileHashSupportedTypesHex ( string  filePath,
string  hashValue 
)
inlinestatic

Chechs all supported types of hash value of a file.

Returns the hash type if the hash value matches the hash value of that type of the specified file, or HashType.None if the specified hash value doesn't match the hash value of any supported type of the specified file.

Parameters
inputFilePathPath to the file whose hash value is checked.
HashValueSupposed hash value whose match with the specified file is checked.
Returns
Type of the hash value that matches the specified hash value of the specified file, or HashType.None if the specified hash value doesn't match the hash value of any supported type of the specified file.

References IG.Lib.Util.AreHexStringsEqual().

Referenced by IG.Forms.HashGeneratorControl.VerifyHash().

static bool IG.Crypto.UtilCrypto.CheckFileHashMd5Hex ( string  filePath,
string  hashValue 
)
inlinestatic

Checks whether the specified MD5 hash value matches the actual hash value of the specified file.

Returns true if the specified hash value matches the actual hash value of the file, and false otherwise.

Parameters
inputFilePathPath to the file whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified file.
Returns
True if the specified file hash value matches the actual value, false otherwise.
static bool IG.Crypto.UtilCrypto.CheckFileHashSha1Hex ( string  filePath,
string  hashValue 
)
inlinestatic

Checks whether the specified SHA-1 hash value matches the actual hash value of the specified file.

Returns true if the specified hash value matches the actual hash value of the file, and false otherwise.

Parameters
inputFilePathPath to the file whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified file.
Returns
True if the specified file hash value matches the actual value, false otherwise.
static bool IG.Crypto.UtilCrypto.CheckFileHashSha256Hex ( string  filePath,
string  hashValue 
)
inlinestatic

Checks whether the specified SHA-256 hash value matches the actual hash value of the specified file.

Returns true if the specified hash value matches the actual hash value of the file, and false otherwise.

Parameters
inputFilePathPath to the file whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified file.
Returns
True if the specified file hash value matches the actual value, false otherwise.
static bool IG.Crypto.UtilCrypto.CheckFileHashSha512Hex ( string  filePath,
string  hashValue 
)
inlinestatic

Checks whether the specified SHA-512 hash value matches the actual hash value of the specified file.

Returns true if the specified hash value matches the actual hash value of the file, and false otherwise.

Parameters
inputFilePathPath to the file whose hash value is checked.
HashValueSupposed hash value whose validity is checked for the specified file.
Returns
True if the specified file hash value matches the actual value, false otherwise.
static SymmetricAlgorithmType [] IG.Crypto.UtilCrypto.GetSymmetricAlgorithmTypes ( )
inlinestatic

Returns all symmetric encryption algorithm types contained in the enumeration SymmetricAlgorithmType

References IG.Lib.Util.LockGlobal.

static SymmetricAlgorithmType IG.Crypto.UtilCrypto.GetSymmetricAlgorithmType ( string  typeString)
inlinestatic

Returns the SymmetricAlgorithmType value corresponding to the specified string.

This function enables selection of algorithms with strings that can have arbitrary capitalization of their letters, and are thus friendly for user insertion.

Parameters
typeStringString that represents the symmetric encryption algorithm type.

Referenced by IG.Script.ScriptAppBase.CryptoFunctionEncrypt_OLD_TO_DELETE(), and IG.Crypto.CryptoManager.ParseCommandlineParameters().

static SymmetricAlgorithmType IG.Crypto.UtilCrypto.GetSymmetricAlgorithmType ( SymmetricAlgorithm  algorithmObject)
inlinestatic

Returns the symmetric encryption algorithm type, i.e. an enumeration of type SymmetricAlgorithmType, for the specified symmetric encryption algorithm object.

Parameters
algorithmObjectSymmetric algorithm object for which type enumeration is returned.
Returns
The type enumeration corresponding to the specified algorithm, or 0 (None) if the algorithm is null or not contained in the enumeration.
static string IG.Crypto.UtilCrypto.SymmetricAlgorithmTypeToString ( SymmetricAlgorithmType  algorithmType)
inlinestatic

Returns standard string representation of the specified symmetric encryption algorithm type.

Parameters
algorithmTypeSymmetric encryption algorithm type whose string representation is returned.

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static SymmetricAlgorithm IG.Crypto.UtilCrypto.GetSymmetricEncryptionAlgorithm ( SymmetricAlgorithmType  algorithmType)
inlinestatic

Returns the appropriate symmetric encryption algorithm according to the specified hash type, or null if the type is not recognized or the method is not implemented for that type.

Parameters
algorithmTypeSpecification of the symmetric encryption algorithm type.
static bool IG.Crypto.UtilCrypto.IsCorrectSymmetricEncryptionAlgorithm ( SymmetricAlgorithm  algorithm,
SymmetricAlgorithmType  algorithmType 
)
inlinestatic

Returns true if the specified symmetric encryption algorithm corresponds the type specification, false otherwise.

If the specified algorithm is null or the specified type is unknown then false is returned.

Parameters
algorithmTypeSpecification of the symmetric encryption algorithm type.
algorithmAlgorithm that is checked for type correctness.
static byte [] IG.Crypto.UtilCrypto.PadToAlgorithmBlocksizeCyclic ( byte[]  byteArray,
int  blockSize,
bool  truncateIfLarger = false 
)
inlinestatic

For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified initialization array is returned, otherwise the modified array that fits the required block size is returned (i.e. has integer number of blocks).

Bytes that are missing to the last full block are filled cyclically with the original bytes from teh beginning.

Parameters
byteArrayOriginal array provided for the algorithm with specified block size.
blockSizeBlock size of the algorithm for which array is repaired, in bytes.

Warning: Algorithms specify block size in bits, not in bytes.

Parameters
truncateIfLargerIf true then the byte array is truncated to the block size if it is larger than it.

Warning: this can only be done with the key and initialization vector, but not with data!!

Returns

An array that is of valid size for the algorithm.

If the original initialization vector size matches the required one, the vector is unmodified.

If the original vector is not a multiple of block size, it is padded by its initial bytes until the desired length.

Referenced by IG.Crypto.PasswordAlgorithmNone.GetBytesInternal().

static byte [] IG.Crypto.UtilCrypto.PadToAlgorithmBlocksizeZero ( byte[]  byteArray,
int  blockSize,
bool  truncateIfLarger = false 
)
inlinestatic

For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified initialization array is returned, otherwise the modified array that fits the required block size is returned (i.e. has integer number of blocks).

Bytes that are missing to the last full block are filled cyclically with the original bytes from teh beginning.

Parameters
byteArrayOriginal array provided for the algorithm with specified block size.
blockSizeBlock size of the algorithm for which array is repaired.
truncateIfLargerIf true then the byte array is truncated to the block size if it is larger than it.

Warning: this can only be done with the key and initialization vector, but not with data!!

Returns

An array that is of valid size for the algorithm.

If the original initialization vector size matches the required one, the vector is unmodified.

If the original vector is not a multiple of block size, it is padded by its initial bytes until the desired length.

static byte [] IG.Crypto.UtilCrypto.PadToSymmetricAlgorithmBlocksizeCyclic ( byte[]  byteArray,
SymmetricAlgorithm  algorithm,
bool  truncateIfLarger = false 
)
inlinestatic

For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified array is returned, otherwise the modified array that fits the required block size is returned. The array size must be mltiple of the block size.

Bytes that are missing to the last full block are filled cyclically with the original bytes from teh beginning.

Parameters
byteArrayOriginal byte array provided for the algorithm.
algorithmSymmetric algorithm that is used for encryption/decryption. Object is used to query and eventually set the block sizes.
truncateIfLargerIf true then the byte array is truncated to the block size if it is larger than it.

Warning: this can only be done with the key and initialization vector, but not with data!!

Returns

An array of bytes that is of valid size for the algorithm.

If the original initialization vector size matches the required one, the array is unmodified.

If the original array is not a multiple of block size, it is padded by its initial bytes until the desired length.

static byte [] IG.Crypto.UtilCrypto.PadToSymmetricAlgorithmBlocksizeZero ( byte[]  byteArray,
SymmetricAlgorithm  algorithm,
bool  truncateIfLarger = false 
)
inlinestatic

For the specified symmetric encryption algorithm, this function takes the specified byte array and checks if the array is of valid size. If yes then the unmodified array is returned, otherwise the modified array that fits the required block size is returned. The array size must be mltiple of the block size.

Bytes that are missing to the last full block are filled cyclically with the original bytes from teh beginning.

Parameters
byteArrayOriginal byte array provided for the algorithm.
algorithmSymmetric algorithm that is used for encryption/decryption. Object is used to query and eventually set the block sizes.
truncateIfLargerIf true then the byte array is truncated to the block size if it is larger than it.

Warning: this can only be done with the key and initialization vector, but not with data!!

Returns

An array of bytes that is of valid size for the algorithm.

If the original initialization vector size matches the required one, the array is unmodified.

If the original array is not a multiple of block size, it is padded by its initial bytes until the desired length.

static byte [] IG.Crypto.UtilCrypto.GetValidSymmetricAlgorithmKey ( byte[]  key,
SymmetricAlgorithm  algorithm 
)
inlinestatic

For the specified symmetric encryption algorithm, this function takes the specified key and checks if the key is of valid size. If yes then the unmodified key is returned, otherwise the modified key that fits the required size is returned.

Parameters
keyOriginal key provided for the algorithm.
algorithmSymmetric algorithm that is used for encryption/decryption. Object is used to query and eventually set the key sizes.
Returns

A key that is of valid size for the algorithm.

If the original key size matches the required one, the key is unmodified.

If the original key is larger than the required one, the first bytes of the provided key are used in the returned key.

If the provided key is smaller than the erquired key size then bytes in the returned key are cyclically repeated bytes from the original key.

static byte [] IG.Crypto.UtilCrypto.GetValidSymmetricAlgorithmIV ( byte[]  IV,
SymmetricAlgorithm  algorithm 
)
inlinestatic

For the specified symmetric encryption algorithm, this function takes the specified initialization vector and checks if the vector is of valid size. If yes then the unmodified IV is returned, otherwise the modified IV that fits the required size is returned.

Parameters
IVOriginal initialization vector provided for the algorithm.
algorithmSymmetric algorithm that is used for encryption/decryption. Object is used to query and eventually set the initialization vector sizes (i.e., the block sizes).
Returns

An initialization vector that is of valid size for the algorithm (i.e. is of the same size as block size).

If the original key size matches the required one, the IV is unmodified.

If the original IV is larger than the required one, the first bytes of the provided IV are used in the returned IV.

If the provided key is smaller than the erquired IV size (i.e. block size) then bytes in the returned IV are cyclically repeated bytes from the original IV.

static int IG.Crypto.UtilCrypto.GetLargestSymmetricAlgorithmKeySize ( SymmetricAlgorithm  algorithm)
inlinestatic

Returns the largest possible key siye, in bits, for the spcified symmetric encryption algorithm.

Parameters
algorithmAlgorithm whose largest possible key size is returned.
static int IG.Crypto.UtilCrypto.SetLargestSymmetricAlgorithmKeySize ( SymmetricAlgorithm  algorithm)
inlinestaticprivate

On the specified symmetric encryption algorythm, sets the largest possible key size, in bits, for the spcified symmetric encryption algorithm.

Parameters
algorithmAlgorithm whose largest possible key size is returned.
Returns
Actual key size on the algorithm after the operation (should be the largest possible key).
static int IG.Crypto.UtilCrypto.GetLargestSymmetricAlgorithmBlockSize ( SymmetricAlgorithm  algorithm)
inlinestatic

Returns the largest possible block siye, in bits, for the spcified symmetric encryption algorithm.

Parameters
algorithmAlgorithm whose largest possible block size is returned.
static int IG.Crypto.UtilCrypto.SetLargestSymmetricAlgorithmBlockSize ( SymmetricAlgorithm  algorithm)
inlinestaticprivate

On the specified symmetric encryption algorithm, sets the largest possible block size, in bits, for the spcified symmetric encryption algorithm.

Parameters
algorithmAlgorithm whose largest possible block size is set.
Returns
Actual block size on the algorithm after the operation (should be the largest possible block size).
static void IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmBasic ( byte[]  passwordBytes,
byte[]  passwordSalt,
ref byte[]  key,
ref byte[]  IV,
SymmetricAlgorithmType  algorithmType,
ref SymmetricAlgorithm  algorithm,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Prepares the symmetric algorithm, initialization vector, and key before encryption or decryption takes place.

Creates the algorithm if necessary, changes algorithm parameters (such as key size) when applicable, and checks and corrects the key and initialization vector, if necessary.

Parameters
keyKey used. Method checks that the key is of correct size and corrects it when necessary.
IVInitialization vector used. Method checks that it is consistent with the algorithm's block size and corrects it if it is not.
algorithmTypeAlgorithm type. If the algorithm is not specified then it is created anew according to this parameter.
algorithmAlgorithm used for encryption. If null it is created. If specified then it is checked that it corresponds to the type specified by algorithmType .
useLargestKeyIf true then algorithm parameters are set (if necessary) in such a way that the largest hey length supported by the algorithm is used.
useLargestBlockIf true then algorithm parameters are set (if necessary) in such a way that the largest hey length supported by the algorithm is used.

References IG.Crypto.PasswordAlgorithmBase.GetBytes(), IG.Crypto.UtilCrypto.GetPasswordAlgorithm(), IG.Crypto.PasswordAlgorithmBase.Init(), IG.Crypto.ConstCrypto.MinPasswordLength, IG.Crypto.ConstCrypto.MinPasswordSaltLength, and IG.Crypto.UtilCrypto.PasswordAlgorithmTypeToString().

static byte [] IG.Crypto.UtilCrypto.EncryptBasic ( byte[]  data,
byte[]  passwordBytes,
byte[]  passwordSalt,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the specified byte array by a symmetric encryption algorithm and returns encrypted bytes.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
dataData to be encrypted.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
SaltBytesSalt that is prepended the data before encryption.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

References IG.Crypto.ConstCrypto.MinPasswordSaltLength.

static byte [] IG.Crypto.UtilCrypto.DecryptBasic ( byte[]  data,
byte[]  passwordBytes,
byte[]  passwordSalt,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Decrypts the specified byte array by a symmetric algorithm and returns decrypted data.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
dataData to be decrypted.
keySecret key used to decrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
numSaltBytesLength of salt, which must be accounted for when decrypting.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Decrypted data as byte array.
static string IG.Crypto.UtilCrypto.EncryptStringBasic ( string  stringToEncrypt,
byte[]  passwordBytes,
byte[]  passwordSalt,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the specified string, using the specified symmetric algorithm, key, and initialization vector, and returns the ToBase64 string representation of the encrypted bytes.

Parameters
stringToEncryptString that is encrypted.
keySecret key used in encryption.
initializationVectorInitialization vector used in encryption. Necessary for stronger encryption (othervise repeating input blocks would cause repeating output blocks).
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with <param name="algorithmType", or null.
SaltBytesSalt that is prepended the data before encryption.
useLargestKeyIf true then the algorithm will be modified in such a way that it uses the largest possible key for this kind of algorithm.
useLargestBlockIf true then the algorithm will be modified in such a way that it uses the largest possible block for this kind of algorithm.
Returns
Base64 string representation of the encrypted string bytes.

References IG.Crypto.ConstCrypto.MinPasswordSaltLength.

static string IG.Crypto.UtilCrypto.DecryptStringBasic ( string  cipherText,
byte[]  passwordBytes,
byte[]  passwordSalt,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Derypts the specified string from encryted byte array, using the specified symmetric algorithm, key, and initialization vector.

Parameters
cipherTextBase64 string representation of the byte array containing the encrypted original string.
keySecret key used in encryption.
initializationVectorInitialization vector used in encryption. Necessary for stronger encryption (othervise repeating input blocks would cause repeating output blocks).
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with <param name="algorithmType", or null.
numSaltBytesLength of salt, which must be accounted for when decrypting.
useLargestKeyIf true then the algorithm will be modified in such a way that it uses the largest possible key for this kind of algorithm.
useLargestBlockIf true then the algorithm will be modified in such a way that it uses the largest possible block for this kind of algorithm.
Returns
Original string, provided that input arguments are correct.
static void IG.Crypto.UtilCrypto.EncryptFileBasic ( string  inputFilePath,
string  outputFilePath,
byte[]  passwordBytes,
byte[]  passwordSalt,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
int  bufferSize = ConstCrypto.FileBufferSize,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the data from the specified input file by a symmetric encryption algorithm and writes encrypted data to the specified output file.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
inputFilePathPath to the input file from which data is encrypted. The file must be exist and be readable.
deletedFilePathPath to the output file to which encrypted data is written. The file must be writable and will be overwritten if it already exists.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream. Buffer makes possible to work on very large streams efficiently.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

References IG.Crypto.ConstCrypto.MinPasswordSaltLength.

static void IG.Crypto.UtilCrypto.DecryptFileBasic ( string  inputFilePath,
string  outputFilePath,
byte[]  passwordBytes,
byte[]  passwordSalt,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
int  bufferSize = ConstCrypto.FileBufferSize,
PasswordAlgorithmType  pwdType = PasswordAlgorithmType.Default,
int  pwdNumIterations = 1000,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Decrypts the data from the specified input file by a symmetric encryption algorithm and writes decrypted data to the specified output file.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
inputFilePathPath to the input file from which data is encrypted. The file must be exist and be readable.
deletedFilePathPath to the output file to which encrypted data is written. The file must be writable and will be overwritten if it already exists.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream. Buffer makes possible to work on very large streams efficiently.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.
static void IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmPlain ( ref byte[]  key,
ref byte[]  IV,
SymmetricAlgorithmType  algorithmType,
ref SymmetricAlgorithm  algorithm,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Prepares the symmetric algorithm, initialization vector, and key before encryption or decryption takes place.

Creates the algorithm if necessary, changes algorithm parameters (such as key size) when applicable, and checks and corrects the key and initialization vector, if necessary.

Parameters
keyKey used. Method checks that the key is of correct size and corrects it when necessary.
IVInitialization vector used. Method checks that it is consistent with the algorithm's block size and corrects it if it is not.
algorithmTypeAlgorithm type. If the algorithm is not specified then it is created anew according to this parameter.
algorithmAlgorithm used for encryption. If null it is created. If specified then it is checked that it corresponds to the type specified by algorithmType .
useLargestKeyIf true then algorithm parameters are set (if necessary) in such a way that the largest hey length supported by the algorithm is used.
useLargestBlockIf true then algorithm parameters are set (if necessary) in such a way that the largest hey length supported by the algorithm is used.

Referenced by IG.Crypto.UtilCrypto.DecryptPlain(), and IG.Crypto.UtilCrypto.EncryptPlain().

static void IG.Crypto.UtilCrypto.EncryptPlain ( byte[]  data,
Stream  outputStream,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the specified byte array by a symmetric encryption algorithm and writes encrypted data to the specified output stream that must be open for writing.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
dataData to be encrypted.
outputStreamStream to which decrypted data is written. The stream must be open for writing and should be closed by the caller of this method.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
SaltBytesSalt that is prepended the data before encryption.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

References IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmPlain().

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static void IG.Crypto.UtilCrypto.DecryptPlain ( byte[]  data,
Stream  outputStream,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Decrypts the specified byte array by a symmetric algorithm and writes decrypted data to the specified output stream.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
dataData to be decrypted.
outputStreamStream to which decrypted data is written. The stream must be open for writing and should be closed by the caller of this method.
keySecret key used to decrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
numSaltBytesLength of salt, which must be accounted for when decrypting.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Decrypted data as byte array.

References IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmPlain().

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static byte [] IG.Crypto.UtilCrypto.EncryptPlain ( byte[]  data,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the specified byte array by a symmetric encryption algorithm and returns encrypted bytes.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
dataData to be encrypted.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
SaltBytesSalt that is prepended the data before encryption.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.
static byte [] IG.Crypto.UtilCrypto.DecryptPlain ( byte[]  data,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Decrypts the specified byte array by a symmetric algorithm and returns decrypted data.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
dataData to be decrypted.
keySecret key used to decrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
numSaltBytesLength of salt, which must be accounted for when decrypting.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Decrypted data as byte array.
static string IG.Crypto.UtilCrypto.EncryptStringPlain ( string  stringToEncrypt,
byte[]  key,
byte[]  initializationVector,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the specified string, using the specified symmetric algorithm, key, and initialization vector, and returns the Base64 string representation of the encrypted bytes.

Parameters
stringToEncryptString that is encrypted.
keySecret key used in encryption.
initializationVectorInitialization vector used in encryption. Necessary for stronger encryption (othervise repeating input blocks would cause repeating output blocks).
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with <param name="algorithmType", or null.
SaltBytesSalt that is prepended the data before encryption.
useLargestKeyIf true then the algorithm will be modified in such a way that it uses the largest possible key for this kind of algorithm.
useLargestBlockIf true then the algorithm will be modified in such a way that it uses the largest possible block for this kind of algorithm.
Returns
Base64 string representation of the encrypted string bytes.

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static string IG.Crypto.UtilCrypto.DecryptStringPlain ( string  cipherText,
byte[]  key,
byte[]  initializationVector,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Derypts the specified string from encryted byte array, using the specified symmetric algorithm, key, and initialization vector.

Parameters
cipherTextBase64 string representation of the byte array containing the encrypted original string.
keySecret key used in encryption.
initializationVectorInitialization vector used in encryption. Necessary for stronger encryption (othervise repeating input blocks would cause repeating output blocks).
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with <param name="algorithmType", or null.
numSaltBytesLength of salt, which must be accounted for when decrypting.
useLargestKeyIf true then the algorithm will be modified in such a way that it uses the largest possible key for this kind of algorithm.
useLargestBlockIf true then the algorithm will be modified in such a way that it uses the largest possible block for this kind of algorithm.
Returns
Original string, provided that input arguments are correct.

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static byte [] IG.Crypto.UtilCrypto.EncryptStringToBytesPlain ( string  stringToEncrypt,
byte[]  key,
byte[]  initializationVector,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the specified string to a byte array, using the specified symmetric algorithm, key, and initialization vector.

Parameters
stringToEncryptString that is encrypted.
keySecret key used in encryption.
initializationVectorInitialization vector used in encryption. Necessary for stronger encryption (othervise repeating input blocks would cause repeating output blocks).
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with <param name="algorithmType", or null.
SaltBytesSalt that is prepended the data before encryption.
useLargestKeyIf true then the algorithm will be modified in such a way that it uses the largest possible key for this kind of algorithm.
useLargestBlockIf true then the algorithm will be modified in such a way that it uses the largest possible block for this kind of algorithm.
Returns
Array of bytes containing encrypted string.
static string IG.Crypto.UtilCrypto.DecryptStringFromBytesPlain ( byte[]  cipherText,
byte[]  key,
byte[]  initializationVector,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.Default,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Derypts the specified string from encryted byte array, using the specified symmetric algorithm, key, and initialization vector.

Parameters
cipherTextByte array containing the encrypted original string.
keySecret key used in encryption.
initializationVectorInitialization vector used in encryption. Necessary for stronger encryption (othervise repeating input blocks would cause repeating output blocks).
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with <param name="algorithmType", or null.
numSaltBytesLength of salt, which must be accounted for when decrypting.
useLargestKeyIf true then the algorithm is modified (if necessary) in such a way that the largest possible key size is used.
useLargestBlockIf true then the algorithm is modified in such a way that the largest possible block size is used.
Returns
Original string, provided that input arguments are correct.
static void IG.Crypto.UtilCrypto.EncryptPlain ( Stream  inputStream,
Stream  outputStream,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
int  bufferSize = ConstCrypto.FileBufferSize,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the data from the specified input stream by a symmetric encryption algorithm and writes encrypted data to the specified output stream.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
inputStreamInput stream from which data is encrypted. The stream must be open for reading and should be closed by the caller of this method.
outputStreamStream to which encrypted data is written. The stream must be open for writing and should be closed by the caller of this method.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream. Buffer makes possible to work on very large streams efficiently.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

References IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmPlain().

static void IG.Crypto.UtilCrypto.DecryptPlain ( Stream  inputStream,
Stream  outputStream,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
int  bufferSize = ConstCrypto.FileBufferSize,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Decrypts the data from the specified input stream by a symmetric encryption algorithm and writes decrypted data to the specified output stream.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
inputStreamInput stream from which data is decrypted. The stream must be open for reading and should be closed by the caller of this method.
outputStreamStream to which decrypted data is written. The stream must be open for writing and should be closed by the caller of this method.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream. Buffer makes possible to work on very large streams efficiently.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

References IG.Crypto.UtilCrypto.PrepareSymmetricAllgorithmPlain().

static void IG.Crypto.UtilCrypto.EncryptFilePlain ( string  inputFilePath,
string  outputFilePath,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
byte[]  saltBytes = null,
int  bufferSize = ConstCrypto.FileBufferSize,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Encrypts the data from the specified input file by a symmetric encryption algorithm and writes encrypted data to the specified output file.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
inputFilePathPath to the input file from which data is encrypted. The file must be exist and be readable.
deletedFilePathPath to the output file to which encrypted data is written. The file must be writable and will be overwritten if it already exists.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream. Buffer makes possible to work on very large streams efficiently.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static void IG.Crypto.UtilCrypto.DecryptFilePlain ( string  inputFilePath,
string  outputFilePath,
byte[]  key,
byte[]  IV,
SymmetricAlgorithmType  algorithmType = SymmetricAlgorithmType.None,
SymmetricAlgorithm  algorithm = null,
int  numSaltBytes = 0,
int  bufferSize = ConstCrypto.FileBufferSize,
bool  useLargestKey = false,
bool  useLargestBlock = false 
)
inlinestatic

Decrypts the data from the specified input file by a symmetric encryption algorithm and writes decrypted data to the specified output file.

If the algorithm is not specified then it is provided by the system, but in this case both the key and the initialization vector must be specified.

If algorithm is specified then the key and initialization vector can be generated by the algorithm and retrieved from the algorithm after the call.

Parameters
inputFilePathPath to the input file from which data is encrypted. The file must be exist and be readable.
deletedFilePathPath to the output file to which encrypted data is written. The file must be writable and will be overwritten if it already exists.
keySecret key used to encrypt the data.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
IVInitialization vector. It can be public and stored together with encrypted data, but it is advised that the vecor is randomly generated for each session or each encryption.

If not specified but algorithm is specified, it is randomly generated and stored by the algorithm.

Parameters
algorithmTypeType of the algorithm used.
algorithmAlgoritgm used.

If specified then key and IV can be generated and stored by the algorithm. Algorithm type must correspond to the specified type.

If not specified then it is generated anew.

Parameters
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream. Buffer makes possible to work on very large streams efficiently.
useLargestKeyIf true then algorithm is eventually modified in such a way that it uses the largest possible key size.
useLargestBlockIf true then algorithm is eventually modified in such a way that it uses the largest possible block size.
Returns
Encrypted data as byte array.

Referenced by IG.Crypto.CryptoManager.AppEncryptSymmetricAll().

static AsymmetricAlgorithmType [] IG.Crypto.UtilCrypto.GetAsymmetricAlgorithmTypes ( )
inlinestatic

Returns all asymmetric encryption algorithm types contained in the enumeration AsymmetricAlgorithmType

References IG.Lib.Util.LockGlobal.

static AsymmetricAlgorithmType IG.Crypto.UtilCrypto.GetAsymmetricAlgorithmType ( string  typeString)
inlinestatic

Returns the AsymmetricAlgorithmType value corresponding to the specified string.

Parameters
typeStringString that represents the asymmetric encryption algorithm type.

Referenced by IG.Crypto.CryptoManager.ParseCommandlineParameters().

static AsymmetricAlgorithmType IG.Crypto.UtilCrypto.GetAsymmetricAlgorithmType ( AsymmetricAlgorithm  algorithmObject)
inlinestatic

Returns the asymmetric encryption algorithm type, i.e. an enumeration of type SymmetricAlgorithmType, for the specified asymmetric encryption algorithm object.

Parameters
algorithmObjectAsymmetric algorithm object for which type enumeration is returned.
Returns
The type enumeration corresponding to the specified algorithm, or 0 (None) if the algorithm is null or not contained in the enumeration.
static string IG.Crypto.UtilCrypto.AsymmetricAlgorithmTypeToString ( AsymmetricAlgorithmType  algorithmType)
inlinestatic

Returns standard string representation of the specified asymmetric encryption algorithm type.

Parameters
algorithmTypeAsymmetric encryption algorithm type whose string representation is returned.
static AsymmetricAlgorithm IG.Crypto.UtilCrypto.GetAsymmetricEncryptionAlgorithm ( AsymmetricAlgorithmType  algorithmType)
inlinestatic

Returns the appropriate asymmetric algorithm according to the specified hash type, or null if the type is not recognized or the method is not implemented for that type.

Parameters
algorithmTypeSpecification of the asymmetric encryption algorithm type.
static bool IG.Crypto.UtilCrypto.IsCorrectAsymmetricEncryptionAlgorithm ( AsymmetricAlgorithm  algorithm,
AsymmetricAlgorithmType  algorithmType 
)
inlinestatic

Returns true if the specified asymmetric encryption algorithm corresponds the type specification, false otherwise.

If the specified algorithm is null or the specified type is unknown then false is returned.

Parameters
algorithmTypeSpecification of the asymmetric encryption algorithm type.
algorithmAlgorithm that is checked for type correctness.
static int IG.Crypto.UtilCrypto.GetLargestAsymmetricAlgorithmKeySize ( AsymmetricAlgorithm  algorithm)
inlinestatic

Returns the largest possible key size, in bits, for the spcified symmetric encryption algorithm.

Parameters
algorithmAlgorithm whose largest possible key size is returned.
static int IG.Crypto.UtilCrypto.SetLargestAsymmetricAlgorithmKeySize ( AsymmetricAlgorithm  algorithm)
inlinestaticprivate

On the specified asymmetric encryption algorithm, sets the largest possible key size, in bits, for the corresponding asymmetric encryption algorithm.

Parameters
algorithmAlgorithm whose largest possible key size is returned.
Returns
Actual key size on the algorithm after the operation (should be the largest possible key).
static byte [] IG.Crypto.UtilCrypto.GetValidAsymmetricAlgorithmKey ( byte[]  key,
AsymmetricAlgorithm  algorithm,
bool  useLargestKey = false 
)
inlinestatic

For the specified asymmetric encryption algorithm, this function takes the specified key and checks if the key is of valid size. If yes then the unmodified key is returned, otherwise the modified key that fits the required size is returned.

Parameters
initializationVectorOriginal key provided for the algorithm.
algorithmAsymmetric algorithm that is used for encryption/decryption. Object is used to query and eventually set the key sizes.
useLargestBlockIf true then the specified algorithm is first modified in such a way that it uses the maximal possible key length for the specific kind of algorithm.
Returns

A key that is of valid size for the algorithm.

If the original key size matches the required one, the key is unmodified.

If the original key is larger than the required one, the first bytes of the provided key are used in the returned key.

If the provided key is smaller than the erquired key size then bytes in the returned key are cyclically repeated bytes from the original key.

static string IG.Crypto.UtilCrypto.IgGetSaltSuffix ( int  whichSalt)
inlinestatic

Returns the specified standard IGLib salt string.

There are several uses of salt strings:

- they are appended or prepended to passwords before hashing.

Parameters
whichSaltIndex of the standard IGLib salt string.
Returns
The standard IGLib salt string corresponding to the specified index.
static int IG.Crypto.UtilCrypto.IgGetNumSaltSuffices ( )
inlinestatic

Returns the number of standard IGLib salt strings.

Returns
The number of standard IGLib salt strings.
See also
GetIGLibSalt

Member Data Documentation

int IG.Crypto.UtilCrypto._outputLevel = 1
staticprivate
object IG.Crypto.UtilCrypto._lockStatic = null
staticprivate
PasswordAlgorithmType [] IG.Crypto.UtilCrypto._passwordAlgorithmTypes = null
staticprivate
PasswordAlgorithmBase IG.Crypto.UtilCrypto._passwordAlgorithmNone = null
staticprivate
RNGCryptoServiceProvider IG.Crypto.UtilCrypto._rng = null
staticprivate
HashType [] IG.Crypto.UtilCrypto._hashTypes = null
staticprivate
SymmetricAlgorithmType [] IG.Crypto.UtilCrypto._symmetricTypes = null
staticprivate
AsymmetricAlgorithmType [] IG.Crypto.UtilCrypto._asymmetricTypes = null
staticprivate
string [] IG.Crypto.UtilCrypto._igLibLongSaltSuffices
staticprivate
Initial value:
= new string[] {
"0586297593_hc94kglh9kfjhtgk04vnbtheli9f84_IGLib_by_Igor_Gresovnik_k8ktkg9mgrn48vg94f9bkjd8_79384659674",
"74073659573_l9hfnci85vj7fl58f799aj5kla8s9_IGLib_by_Igor_Gresovnik_b098jdk87jflg274kglmng02_73608109847"
}

An array of standard IGLib salt suffices.

Warnings:

- Hard coding salts is generally not OK, it is important that salts are random and salts can be stored together with enxrypted data.

- This array should not be modifiable.

- Elements of this array may not change over time. Only new elements can be added.

Property Documentation

int IG.Crypto.UtilCrypto.OutputLevel
staticget

Output level for static methods of the current utility class.

Warning: This field can be removed at any time.

object IG.Crypto.UtilCrypto.LockStatic
staticget

Locking object for static methods and properties of this class.

Encoding IG.Crypto.UtilCrypto.StringEncoding
staticget
RNGCryptoServiceProvider IG.Crypto.UtilCrypto.Rng
staticgetprivate

Object used to generate random bytes.

Object is created on demand (layzy evaluation). Ony one object is used through appllication lifetime.


The documentation for this class was generated from the following file: