IGLib  1.7.2
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
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 hashRet value, in bytes, for the specified hashRet algorithm. More...
 
static int GetHashLengthHex (HashType hashType)
 Returns length of the HEXADECIMAL hashRet string for the specified hashRet 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 hashRet type. More...
 
static HashAlgorithm GetHashAlgorithm (HashType hashType)
 Returns the appropriate hashRet algorithm according to the specified hashRet 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 hashRet algorithm corresponds the type specification, false otherwise. More...
 
static void ParseHashFile (string filePath, ref List< string[]> hashList)
 Parses the file containing hashRet values of one or more files, and adds the parsed pairs {hashRet, inputFilePath} to the specified list. More...
 
static void ParseHashFileString (string str, ref List< string[]> hashList)
 Parses the string containing hashRet values of one or more files, and adds the parsed pairs {hashRet, inputFilePath} to the specified list. More...
 
static byte[] GetHashBytes (byte[] bytesToHash, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hashRet (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 hashRet string of the specified kind of the specified byte array. More...
 
static string GetHashMd5Hex (byte[] bytesToHash)
 Computes and returns the MD5 hashRet string of the specified array of bytes. More...
 
static string GetHashSha1Hex (byte[] bytesToHash)
 Computes and returns the SHA1 hashRet string of the specified array of bytes. More...
 
static string GetHashSha256Hex (byte[] bytesToHash)
 Computes and returns the SHA256 hashRet string of the specified array of bytes. More...
 
static string GetHashSha512Hex (byte[] bytesToHash)
 Computes and returns the SHA512 hashRet string of the specified array of bytes. More...
 
static bool CheckHashHex (byte[] bytesToCheck, string hashValue, HashType hashAlgorithmType)
 Chechs the specified type of hashRet value of a byte array. More...
 
static HashType CheckHashSupportedTypesHex (byte[] bytesToCheck, string hashValue)
 Chechs all supported types of hashRet value of a string. More...
 
static byte[] GetStringHashBytes (string stringToHash, HashType hashType=HashType.Default, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hashRet 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 hashRet string of the specified kind of the specified string. More...
 
static string GetStringHashMd5Hex (string stringToHash)
 Computes and returns the MD5 hashRet string of the specified string. More...
 
static string GetStringHashSha1Hex (string stringToHash)
 Computes and returns the SHA1 hashRet string of the specified string. More...
 
static string GetStringHashSha256Hex (string stringToHash)
 Computes and returns the SHA256 hashRet string of the specified string. More...
 
static string GetStringHashSha512Hex (string stringToHash)
 Computes and returns the SHA512 hashRet 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 hashRet (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 hashRet 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 hashRet 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 hashRet 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 hashRet 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 hashRet 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 hashRet value of a string. More...
 
static HashType CheckStringHashSupportedTypesHex (string stringToCheck, string hashValue)
 Chechs all supported types of hashRet value of a string. More...
 
static bool CheckStringHashMd5Hex (string stringToCheck, string hashValue)
 Checks whether the specified MD5 hashRet value matches the actual hashRet value of the specified string. More...
 
static bool CheckStringHashSha1Hex (string stringToCheck, string hashValue)
 Checks whether the specified SHA-1 hashRet value matches the actual hashRet value of the specified string. More...
 
static bool CheckStringHashSha256Hex (string stringToCheck, string hashValue)
 Checks whether the specified SHA-256 hashRet value matches the actual hashRet value of the specified string. More...
 
static bool CheckStringHashSha512Hex (string stringToCheck, string hashValue)
 Checks whether the specified SHA-512 hashRet value matches the actual hashRet value of the specified string. More...
 
static byte[] GetFileHashBytes (string filePath, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hashRet (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 hashRet string of specified type of the specified stream. More...
 
static string GetFileHashMd5Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the MD5 hashRet string of the specified stream. More...
 
static string GetFileHashSha1Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA1 hashRet string of the specified stream. More...
 
static string GetFileHashSha256Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA256 hashRet string of the specified stream. More...
 
static string GetFileHashSha512Hex (string filePath, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA512 hashRet string of the specified stream. More...
 
static byte[] GetHashBytes (Stream stream, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the hashRet (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 hashRet string of specified type of the specified stream. More...
 
static string GetHashMd5Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the MD5 hashRet string of the specified stream. More...
 
static string GetHashSha1Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA1 hashRet string of the specified stream. More...
 
static string GetHashSha256Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA256 hashRet string of the specified stream. More...
 
static string GetHashSha512Hex (Stream stream, HashAlgorithm cryptoAlgorithm=null)
 Computes and returns the SHA512 hashRet string of the specified stream. More...
 
static bool CheckFileHashHex (string filePath, string hashValue, HashType hashType, HashAlgorithm cryptoAlgorithm=null)
 Chechs the specified type of hashRet value of a file. More...
 
static HashType CheckFileHashSupportedTypesHex (string filePath, string hashValue)
 Chechs all supported types of hashRet value of a file. More...
 
static bool CheckFileHashMd5Hex (string filePath, string hashValue)
 Checks whether the specified MD5 hashRet value matches the actual hashRet value of the specified file. More...
 
static bool CheckFileHashSha1Hex (string filePath, string hashValue)
 Checks whether the specified SHA-1 hashRet value matches the actual hashRet value of the specified file. More...
 
static bool CheckFileHashSha256Hex (string filePath, string hashValue)
 Checks whether the specified SHA-256 hashRet value matches the actual hashRet value of the specified file. More...
 
static bool CheckFileHashSha512Hex (string filePath, string hashValue)
 Checks whether the specified SHA-512 hashRet value matches the actual hashRet 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 hashRet 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 hashRet 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 CspProviderFlags GetCspProviderFlags (string flagString)
 Returns the value of the CspProviderFlags enum corresponding to the specified string. More...
 
static string CspProviderFlagsToString (CspProviderFlags flags)
 Returns standard string representation of the CspProviderFlags enumeration. More...
 
static string ToString (CspKeyContainerInfo keyInfo, int numIndent=0)
 Creates and returns a string that presents the key information contained in the argument keyInfo . More...
 
static string ToString (RSACryptoServiceProvider alg)
 Creates and returns a string containing information about the specified RSA algorithm. More...
 
static string ToString (DSACryptoServiceProvider alg)
 Creates and returns a string containing information about the specified DSA algorithm. More...
 
static string ToString (AsymmetricAlgorithm alg)
 Creates and returns a string containing information about the specified RSA algorithm. More...
 
static string ToString (X509Certificate certificate)
 Returns a readable string representation of the specified certificate. More...
 
static string GetSimpleName (X509Certificate2 cert)
 Returns simple name of the specified cerrtificate. More...
 
static string ToString (X509Certificate2 cert)
 Returns a readable string representation of the specified certificate. More...
 
static string GetCertificateStoreDescription (int outputLevel=0, string storeName=null, int storeLocation=(int) StoreLocation.CurrentUser|(int) StoreLocation.LocalMachine)
 Returns a string that contains human readable description of certificate stores. More...
 
static void GetCertificateStores (ref IList< X509Store > stores, bool clearAtBeginning=true, string storeName=null, int storeLocation=(int) StoreLocation.CurrentUser|(int) StoreLocation.LocalMachine)
 Adds to the specified list all persistent certificate stores that match the criteria specified by parameters. More...
 
static void CloseCertificateStores (IList< X509Store > stores)
 Closes all certificate stores on the list. More...
 
static X509Certificate2 GetCertificate (string privateKeyPassword=null, string certificateFilePath=null, string certificateName=null, string storeName=null, int storeLocation=(int) StoreLocation.CurrentUser|(int) StoreLocation.LocalMachine)
 Obtains and returns the certificate specifid by parameters. More...
 
static string AddCertificateToStore (X509Certificate2 certificate, out bool skipped, out bool overwritten, string certificateStoreName, int storeLocation=(int) StoreLocation.CurrentUser, bool isForceOverwrites=false, bool isSkipOverwrites=false)
 Adds a certificate to the specified certificate store. More...
 
static string DeleteCertificateFromStore (out bool skipped, out bool deleted, string certificateName, string storeName, int storeLocation=(int) StoreLocation.CurrentUser, bool isForceDeletes=false, bool isSkipDeletes=false)
 Deletes the specified certificate to the specified certificate store. More...
 
static string GetAsymmetricalgorithmHash (AsymmetricAlgorithm algorithm, bool includePrivate=false, bool skipPrivateIfNotExportable=false, HashType hashType=HashType.SHA1)
 Returns a hash value for the specified Asymmetric algorithm, which depends on algorithm keys. More...
 
static int GetMaximalAsymmetricTextLength (AsymmetricAlgorithm alg)
 Returns the maximal size of a byte array that can be encrypted by using the specified asymmetric algoritm. More...
 
static bool AsymEncryptionDecryptionTest (string testString, AsymmetricAlgorithm algEnc, AsymmetricAlgorithm algDec=null)
 Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts the specified string. More...
 
static bool AsymEncryptionDecryptionTest (string testString, out string errorString, AsymmetricAlgorithm algEnc, AsymmetricAlgorithm algDec=null)
 Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts the specified string. More...
 
static bool AsymEncryptionDecryptionTest (int length, AsymmetricAlgorithm algEnc, AsymmetricAlgorithm algDec=null)
 Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts a random byte array of the specified size. More...
 
static bool AsymEncryptionDecryptionTest (int length, out string errorString, AsymmetricAlgorithm algEnc, AsymmetricAlgorithm algDec=null)
 Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts a random byte array of the specified size. More...
 
static AsymmetricAlgorithm GetAsymmetricAlgorithm (AsymmetricAlgorithmType algorithmType, string containerName=null, string xmlString=null, CspProviderFlags flags=CspProviderFlags.NoFlags, string certificateFilePath=null, string certificateName=null, string certStore=null)
 Creates (if necessary) and returns a new asymmetric algorithm whose keys are either created or obtained through arguments. More...
 
static void DeleteKeyInCsp (AsymmetricAlgorithmType algorithmType, string containerName)
 Deletes the asymmetric algorithm keys from the specified key container. More...
 
static void PrepareAymmetricAllgorithmBasic (AsymmetricAlgorithmType algorithmType, ref AsymmetricAlgorithm algorithm, string containerName=null, string xmlString=null, CspProviderFlags flags=CspProviderFlags.NoFlags, bool useLargestKey=false)
 
static string EncryptStringAsymShort (string stringToEncrypt, AsymmetricAlgorithm algorithm, AsymmetricAlgorithmType algorithmType=AsymmetricAlgorithmType.None)
 
static string DecryptStringAsymShort (string cipherText, AsymmetricAlgorithm algorithm, AsymmetricAlgorithmType algorithmType=AsymmetricAlgorithmType.None)
 
static byte[] EncryptAsymShort (byte[] originalBytes, AsymmetricAlgorithm algorithm, AsymmetricAlgorithmType algorithmType=AsymmetricAlgorithmType.None)
 
static byte[] DecryptAsymShort (byte[] originalBytes, AsymmetricAlgorithm algorithm, AsymmetricAlgorithmType algorithmType=AsymmetricAlgorithmType.None)
 
static byte[] EncryptAsymShort (byte[] originalBytes, AsymmetricAlgorithmType algorithmType=AsymmetricAlgorithmType.None, AsymmetricAlgorithm algorithm=null, string containerName=null, string xmlString=null, CspProviderFlags flags=CspProviderFlags.NoFlags, bool useLargestKey=false)
 
static byte[] DecryptAsymShort (byte[] originalBytes, AsymmetricAlgorithmType algorithmType=AsymmetricAlgorithmType.None, AsymmetricAlgorithm algorithm=null, string containerName=null, string xmlString=null, CspProviderFlags flags=CspProviderFlags.NoFlags, bool useLargestKey=false)
 
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 bool IsUsed_fOAEP [get]
 Whether to perform direct RSA encryption using OAEP (optimal asymmetric encryption padding - only available on computers running MS Windows XP or later). 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 bool _isUsed_fOAEP1 = false
 
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 hashRet 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

Returns a PasswordAlgorithmType value corresponding to the specified string representation.

Parameters
typeStringString that represents the PasswordAlgorithmType value.

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

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.

Parameters
passwordAlgorithmTypePassword 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
algorithmAlgorithm that is checked for type correctness.
algorithmTypeSpecification of the password derivation nalgorithm type.
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 hashRet value, in bytes, for the specified hashRet algorithm.

-1 is returned if the length is not known.

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

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

-1 is returned if the length is not known.

Parameters
hashTypeType 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 hashRet type.

Referenced by IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER(), 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 hashRet type.

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

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

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

Returns true if the specified cryptographic hashRet 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 hashRet 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 hashRet values of one or more files, and adds the parsed pairs {hashRet, inputFilePath} to the specified list.

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

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

Parameters
filePathPath to the file that is parsed.
hashListList to which which parsed pairs {hashRet, 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(), and IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER().

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

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

String must be in the standard format where each line contains a hashRet value and the path to the corresponding file separated from hashRet 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 {hashRet, 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 hashRet (in form of byte array) of the specified kind of the specified byte array.

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

Parameters
bytesToHashByte array whose hashRet string is calculated.
hashTypeSpecifies 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 hashRet string of the specified kind of the specified byte array.

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

Parameters
bytesToHashByte array whose hashRet string is calculated.
hashTypeSpecifies 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 hashRet string of the specified array of bytes.

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

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

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

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

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

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

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

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

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

Parameters
bytesToCheckString whose hashRet value is checked.
hashValueSupposed hashRet value whose correctness is checked.
hashAlgorithmTypeType of the hashRet value that is checked.
Returns
True if the specified hashRet hashValue actually matches the hashRet 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 hashRet value of a string.

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

Parameters
bytesToCheckString whose hashRet value is checked.
hashValueSupposed hashRet value whose match with the specified string is checked.
Returns
Type of the hashRet value that matches the specified hashRet value of the specified string, or HashType.None if the specified hashRet value doesn't match the hashRet 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 hashRet string of the specified kind of the specified string.

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

Parameters
stringToHashString whose hashRet string is calculated.
hashTypeSpecifies 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 hashRet string of the specified kind of the specified string.

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

Parameters
stringToHashString whose hashRet string is calculated.
hashTypeSpecifies 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.Crypto.UtilCrypto.GetAsymmetricalgorithmHash().

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

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

Parameters
stringToHashString whose cryptographic hashRet is calculated.

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

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

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

Parameters
stringToHashString whose cryptographic hashRet is calculated.

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

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

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

Parameters
stringToHashString whose cryptographic hashRet is calculated.

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

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

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

Parameters
stringToHashString whose cryptographic hashRet is calculated.

Referenced by IG.Forms.HashControl.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 hashRet (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 hashRet type is not known or implemented.

Parameters
stringToHashString whose salted hashRet is to be computed.
hashTypeType 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 hashRet of the specified string, with specified hashRet, and specified number of repetitions of the salted hashRet 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 hashRet 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 hashRet type is not known or implemented.

Parameters
stringToHashString whose salted hashRet is to be computed.
hashTypeType 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 hashRet of the specified string, with specified hashRet, and specified number of repetitions of the salted hashRet 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 hashRet of the specified string, with the specified number of repetitions of the salted hashing algoriithm.

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

Parameters
stringToHashString whose salted hashRet 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 hashRet of the specified string, with specified hashRet, and specified number of repetitions of the salted hashRet calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHashSha1Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

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

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

Parameters
stringToHashString whose salted hashRet 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 hashRet of the specified string, with specified hashRet, and specified number of repetitions of the salted hashRet calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHashSha256Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

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

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

Parameters
stringToHashString whose salted hashRet 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 hashRet of the specified string, with specified hashRet, and specified number of repetitions of the salted hashRet calculation.
static string IG.Crypto.UtilCrypto.GetStringSaltedHashSha512Hex ( string  stringToHash,
string  salt,
int  numIterations = 0 
)
inlinestatic

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

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

Parameters
stringToHashString whose salted hashRet 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 hashRet of the specified string, with specified hashRet, and specified number of repetitions of the salted hashRet calculation.
static bool IG.Crypto.UtilCrypto.CheckStringHashHex ( string  stringToCheck,
string  hashValue,
HashType  hashAlgorithmType 
)
inlinestatic

Chechs the specified type of hashRet value of a string.

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

Parameters
stringToCheckString whose hashRet value is checked.
hashValueSupposed hashRet value whose correctness is checked.
hashAlgorithmTypeType of the hashRet value that is checked.
Returns
True if the specified hashRet hashValue actually matches the hashRet value of the type hashAlgorithmType of the verified string stringToCheck , or false otherwise.

References IG.Lib.Util.AreHexStringsEqual().

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

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

Chechs all supported types of hashRet value of a string.

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

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

References IG.Lib.Util.AreHexStringsEqual().

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

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

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

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

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

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

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

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

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

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

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

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

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

Parameters
stringToCheckString whose hashRet value is checked.
hashValueSupposed hashRet value whose validity is checked for the specified string.
Returns
True if the specified hashRet 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 hashRet (in form of byte array) of specified type of the specified stream.

Parameters
filePathPath to the file whose contents' cryptographic hashRet is calculated.
hashTypeSpecifies 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 hashRet string of specified type of the specified stream.

Parameters
filePathPath to the file whose contents' cryptographic hashRet is calculated.
hashTypeSpecifies 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(), and IG.Script.ScriptAppBase.CryptoFunctionCheckSum_OLD_TO_DELETE_LATER().

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

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

Parameters
filePathPath to the file whose contents' cryptographic hashRet 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.HashControl.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 hashRet string of the specified stream.

Parameters
filePathPath to the file whose contents' cryptographic hashRet 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.HashControl.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 hashRet string of the specified stream.

Parameters
filePathPath to the file whose contents' cryptographic hashRet 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.HashControl.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 hashRet string of the specified stream.

Parameters
filePathPath to the file whose contents' cryptographic hashRet 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.HashControl.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 hashRet (in form of byte array) of specified type of the specified stream.

Parameters
streamStream whose contents' cryptographic hashRet is calculated.
hashTypeType of the hashRet 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 hashRet string of specified type of the specified stream.

Parameters
streamStream whose contents' cryptographic hashRet is calculated.
hashTypeType of the hashRet 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 hashRet string of the specified stream.

Parameters
streamStream whose contents' cryptographic hashRet 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 hashRet string of the specified stream.

Parameters
streamStream whose contents' cryptographic hashRet 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 hashRet string of the specified stream.

Parameters
streamStream whose contents' cryptographic hashRet 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 hashRet string of the specified stream.

Parameters
streamStream whose contents' cryptographic hashRet 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 hashRet value of a file.

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

Parameters
filePathPath to the file whose hashRet value is checked.
hashValueSupposed hashRet value whose correctness is checked.
hashTypeType of the hashRet value that is checked.
cryptoAlgorithmHasihing algoriithm to be used.
Returns
True if hashType specified hashRet hashValue actually matches the hashRet value of the type hashType of the verified file filePath , or false otherwise.

References IG.Lib.Util.AreHexStringsEqual().

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

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

Chechs all supported types of hashRet value of a file.

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

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

References IG.Lib.Util.AreHexStringsEqual().

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

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

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

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

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

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

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

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

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

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

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

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

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

Parameters
filePathPath to the file whose hashRet value is checked.
hashValueSupposed hashRet value whose validity is checked for the specified file.
Returns
True if the specified file hashRet 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.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 hashRet 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
passwordBytesPassword used.
passwordSaltPassword salt used.
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 .
pwdTypeType of the password algorrithm.
pwdNumIterationsNumber of iterations for the password transformation algortgm.
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.
passwordBytesPassword used to generate a secred key used to encrypt the data.

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

Parameters
passwordSaltPassword salt, added to the password when transformed.
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.
pwdTypeType of the algorithm used to transform the password.
pwdNumIterationsNumber of iteration of the password algoriithm.
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.
passwordBytesPassword used to generate a secred key used to encrypt the data.

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

Parameters
passwordSaltPassword salt, added to the password when transformed.
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.
pwdTypePassword algorithm type.
pwdNumIterationsNumber of iterations performed by the password algorithm.
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.
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.
passwordBytesPassword used to generate a secred key used to encrypt the data.

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

Parameters
passwordSaltPassword salt, added to the password when transformed.
algorithmTypeType of the algorithm used for enxryption.
algorithmAgorithm used for encryption. Must be consistend with algorithmType , or null.
saltBytesSalt that is prepended the data before encryption.
pwdTypePassword algorithm type.
pwdNumIterationsNumber of iterations performed by the password algorithm.
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.
passwordBytesPassword used to generate a secred key used to encrypt the data.

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

Parameters
passwordSaltPassword salt, added to the password when transformed.
algorithmTypeType of the algorithm used.
algorithmAgorithm used for encryption. Must be consistend with 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.
pwdTypePassword algorithm that henerated key from the password.
pwdNumIterationsNumber fo iteration of the password 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.
outputFilePathPath to the output file to which encrypted data is written. The file must be writable and will be wasOverwritten if it already exists.
passwordBytesPassword, as byte array.
passwordSaltPassword salt, as byte array.
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, as byte array.
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.
pwdTypePassword algorithm type.
pwdNumIterationsNumber of iterations performed by the password algorithm.
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.
outputFilePathPath to the output file to which encrypted data is written. The file must be writable and will be wasOverwritten if it already exists.
passwordBytesPassword, as byte array.
passwordSaltPassword salt, as byte array.
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.
bufferSizeSize of the intermediate buffer through which we read from input and write to output stream.
Parameters
pwdTypePassword algorithm type.
pwdNumIterationsNumber of iterations performed by the password algorithm.
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 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 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 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 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
saltBytesSalt added to encrypted data.
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.
algorithmAlgorithm 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 the salt that is added to the encrypted data.
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.
outputFilePathPath to the output file to which encrypted data is written. The file must be writable and will be wasOverwritten 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
saltBytesSalt that is added to data before encryption.
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.
outputFilePathPath to the output file to which encrypted data is written. The file must be writable and will be wasOverwritten 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
numSaltBytesLength of the salt that is added to the data befoe encryption.
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(), and IG.Crypto.CryptoManager.ResolveAsymParameters().

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.

Referenced by IG.Crypto.UtilCrypto.DeleteKeyInCsp(), IG.Crypto.UtilCrypto.GetAsymmetricAlgorithm(), and IG.Crypto.UtilCrypto.PrepareAymmetricAllgorithmBasic().

static AsymmetricAlgorithm IG.Crypto.UtilCrypto.GetAsymmetricEncryptionAlgorithm ( AsymmetricAlgorithmType  algorithmType)
inlinestatic

Returns the appropriate asymmetric algorithm according to the specified hashRet 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
keyOriginal key provided for the algorithm.
algorithmAsymmetric algorithm that is used for encryption/decryption. Object is used to query and eventually set the key sizes.
useLargestKeyIf 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 CspProviderFlags IG.Crypto.UtilCrypto.GetCspProviderFlags ( string  flagString)
inlinestatic

Returns the value of the CspProviderFlags enum corresponding to the specified string.

Parameters
flagStringString representation of the flag value of type CspProviderFlags
Returns
CspProviderFlags value corresponding to string parameter.

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

static string IG.Crypto.UtilCrypto.CspProviderFlagsToString ( CspProviderFlags  flags)
inlinestatic

Returns standard string representation of the CspProviderFlags enumeration.

Parameters
flagsAsymmetric encryption algorithm type whose string representation is returned.
static string IG.Crypto.UtilCrypto.ToString ( CspKeyContainerInfo  keyInfo,
int  numIndent = 0 
)
inlinestatic

Creates and returns a string that presents the key information contained in the argument keyInfo .

Parameters
keyInfoInformation about the key pair that is returned in string form.
numIndentIndentation.

Referenced by IG.Crypto.CryptoManager.AppAsymExportKey(), IG.Crypto.CryptoManager.AppAsymKeyInfo(), IG.Crypto.CryptoManager.AppAsymTest(), IG.Crypto.CryptoManager.AppCertInfo(), and IG.Crypto.UtilCrypto.ToString().

static string IG.Crypto.UtilCrypto.ToString ( RSACryptoServiceProvider  alg)
inlinestatic

Creates and returns a string containing information about the specified RSA algorithm.

Parameters
algAlgorithm for which information is returned.

References IG.Crypto.UtilCrypto.ToString().

static string IG.Crypto.UtilCrypto.ToString ( DSACryptoServiceProvider  alg)
inlinestatic

Creates and returns a string containing information about the specified DSA algorithm.

Parameters
algAlgorithm for which information is returned.

References IG.Lib.Util.CollectionToString(), and IG.Crypto.UtilCrypto.ToString().

static string IG.Crypto.UtilCrypto.ToString ( AsymmetricAlgorithm  alg)
inlinestatic

Creates and returns a string containing information about the specified RSA algorithm.

Parameters
algAlgorithm for which information is returned.
static string IG.Crypto.UtilCrypto.ToString ( X509Certificate  certificate)
inlinestatic

Returns a readable string representation of the specified certificate.

To obtain a detailed access to certificate data, the object is first used to create a more advanced X509Certificate2 type of object (which has a contructor that takes its base class) and then string representation is created from thi object, which offers better access to internal data.

Parameters
certificateCertificate whose string representaion is returned.
static string IG.Crypto.UtilCrypto.GetSimpleName ( X509Certificate2  cert)
inlinestatic
static string IG.Crypto.UtilCrypto.ToString ( X509Certificate2  cert)
inlinestatic

Returns a readable string representation of the specified certificate.

Parameters
certCertificate whose string representaion is returned.
static string IG.Crypto.UtilCrypto.GetCertificateStoreDescription ( int  outputLevel = 0,
string  storeName = null,
int  storeLocation = (int) StoreLocation.CurrentUser | (int) StoreLocation.LocalMachine 
)
inlinestatic

Returns a string that contains human readable description of certificate stores.

See also: https://msdn.microsoft.com/en-us/library/System.Security.Cryptography.X509Certificates.X509Store%28v=vs.110%29.aspx

Parameters
outputLevelWhether certificates contained in stores should also be listed (only by names).
storeNameName of the certificate store whose information is included in the string.
storeLocationIndicates the location of certificte store: 1 - current user, 2 - local machine, 0 or 3 - both.

Enumeration StoreLocation can be conveniently used (eventually combined as flags with the OR operator) to define the location.

References IG.Crypto.UtilCrypto.GetSimpleName().

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

static void IG.Crypto.UtilCrypto.GetCertificateStores ( ref IList< X509Store >  stores,
bool  clearAtBeginning = true,
string  storeName = null,
int  storeLocation = (int) StoreLocation.CurrentUser | (int) StoreLocation.LocalMachine 
)
inlinestatic

Adds to the specified list all persistent certificate stores that match the criteria specified by parameters.

Parameters
storesA list to which the matching certificate stores are added.

If it references a variable that is null, the list is created.

If the clearAtBeginning parameter is true then the list is cleared before operation.

Parameters
storeNameName of the certificate store whose information is included in the string.
storeLocationIndicates the location of certificte store: 1 - current user, 2 - local machine, 0 or 3 - both.

Enumeration StoreLocation can be conveniently used (eventually combined as flags with the OR operator) to define the location.

Parameters
clearAtBeginningIf true (which is default value) then the list is cleared before the operation proceeds.

Referenced by IG.Crypto.UtilCrypto.AddCertificateToStore(), and IG.Crypto.UtilCrypto.DeleteCertificateFromStore().

static void IG.Crypto.UtilCrypto.CloseCertificateStores ( IList< X509Store >  stores)
inlinestatic

Closes all certificate stores on the list.

Parameters
storesList of certificate stores that are closed.

Referenced by IG.Crypto.UtilCrypto.AddCertificateToStore(), and IG.Crypto.UtilCrypto.DeleteCertificateFromStore().

static X509Certificate2 IG.Crypto.UtilCrypto.GetCertificate ( string  privateKeyPassword = null,
string  certificateFilePath = null,
string  certificateName = null,
string  storeName = null,
int  storeLocation = (int) StoreLocation.CurrentUser | (int) StoreLocation.LocalMachine 
)
inlinestatic

Obtains and returns the certificate specifid by parameters.

Parameters
privateKeyPasswordPassword to access the certificate's private key.
certificateFilePathName of the file containing the certificate.
certificateNameName of the certificate from certificate store.
storeNameCertificate store frrom which certificate is to be obtained.
storeLocationIndicates location of the certificate store: 1 for current user, 2 for local machine, 0 or 3 for any location, 4 for none.
Returns
Returns the certificate that corresponds to parameters, or null if such a certificate can not be located.

References IG.Crypto.UtilCrypto.GetSimpleName().

Referenced by IG.Crypto.CryptoManager.AppAddCertificate(), and IG.Crypto.CryptoManager.AppCertInfo().

static string IG.Crypto.UtilCrypto.AddCertificateToStore ( X509Certificate2  certificate,
out bool  skipped,
out bool  overwritten,
string  certificateStoreName,
int  storeLocation = (int) StoreLocation.CurrentUser,
bool  isForceOverwrites = false,
bool  isSkipOverwrites = false 
)
inlinestatic

Adds a certificate to the specified certificate store.

Parameters
certificateCertificate to be added to the store.
skippedOutput flag informing whether addition has been wasSkipped (to prevent an overwrite).
overwrittenOutput flag informing whether existing certificate has been wasOverwritten (either due to automatic overwrites specified by parameter isForceOverwrites , or upon user confirmation).
certificateStoreNameName of the certificate store to which the certificate is added.
storeLocationLocation where certificate is added: 1 - current user, 2 - local machine.
isForceOverwritesIf true then overwrites are forcced without asking for user confirmation. In such a case, parameter overwritten is set to true.
isSkipOverwritesIf true then addition is automatically wasSkipped if it would overwrite an existing certificate. In such a case, parameter skipped is set to true.
Returns
Hash value of the public key of the added certificate, or 0 if certificate has not been added.

References IG.Crypto.UtilCrypto.CloseCertificateStores(), IG.Crypto.UtilCrypto.GetAsymmetricalgorithmHash(), IG.Crypto.UtilCrypto.GetCertificateStores(), IG.Crypto.UtilCrypto.GetSimpleName(), and IG.Lib.UtilConsole.Read().

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

static string IG.Crypto.UtilCrypto.DeleteCertificateFromStore ( out bool  skipped,
out bool  deleted,
string  certificateName,
string  storeName,
int  storeLocation = (int) StoreLocation.CurrentUser,
bool  isForceDeletes = false,
bool  isSkipDeletes = false 
)
inlinestatic

Deletes the specified certificate to the specified certificate store.

Parameters
skippedOutput flag informing whether addition has been skipped (to prevent deletion).
deletedOutput flag informing whether existing certificate has been deleeed (either due to automatic deletions specified by parameter isForceDeletes , or upon user confirmation).
certificateNameName of the certificate to be deleted from the store.
storeNameName of the certificate store to which the certificate is added.
storeLocationLocation where certificate is added: 1 - current user, 2 - local machine.
isForceDeletesIf true then deletes are forcced without asking for user confirmation. In such a case, parameter deleted is set to true.
isSkipDeletesIf true then addition is automatically wasSkipped if it would overwrite an existing certificate. In such a case, parameter skipped is set to true.
Returns
Hash value of the public key of the added certificate, or 0 if certificate has not been added.

References IG.Crypto.UtilCrypto.CloseCertificateStores(), IG.Crypto.UtilCrypto.GetAsymmetricalgorithmHash(), IG.Crypto.UtilCrypto.GetCertificateStores(), IG.Crypto.UtilCrypto.GetSimpleName(), and IG.Lib.UtilConsole.Read().

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

static string IG.Crypto.UtilCrypto.GetAsymmetricalgorithmHash ( AsymmetricAlgorithm  algorithm,
bool  includePrivate = false,
bool  skipPrivateIfNotExportable = false,
HashType  hashType = HashType.SHA1 
)
inlinestatic

Returns a hash value for the specified Asymmetric algorithm, which depends on algorithm keys.

The hash vlaue can be used to verify that two algorithm object used actually have the same keys. This is especially useful when encryption is performed on one machine and decryption is performed on another.

See also: RSAParameters", https://msdn.microsoft.com/en-us/library/system.security.cryptography.rsaparameters%28v=vs.110%29.aspx

Parameters
algorithmAlgorithm for which keys' hashRet is returned.
includePrivateWhether private parameters of the asymmetric key contained in the algorithm are taken into account while hassing.

Default is false and it is highly recommended to use only false for this parameter.

Usually using only public parameters should be enough, because it is very unlikely that any key pair would have the same public parameters but different private parameters.

Parameters
skipPrivateIfNotExportableIf true then private parameters are not taken into account when they are not exportable to XML, even when includePrivate = true. If false then exception is thrown in the case that includePrivate is true but private parameters of the keys are not exportable to XML.

Default is false.

Parameters
hashTypeType of the hashing algorithm. Default is HashType.SHA1 and it is recommended that this is not changed.

References IG.Crypto.UtilCrypto.GetStringHashHex(), IG.Crypto.RSA, and IG.Lib.Util.ToHexString().

Referenced by IG.Crypto.UtilCrypto.AddCertificateToStore(), IG.Crypto.CryptoManager.AppAsymExportKey(), IG.Crypto.CryptoManager.AppAsymKeyInfo(), IG.Crypto.CryptoManager.AppCertInfo(), and IG.Crypto.UtilCrypto.DeleteCertificateFromStore().

static int IG.Crypto.UtilCrypto.GetMaximalAsymmetricTextLength ( AsymmetricAlgorithm  alg)
inlinestatic

Returns the maximal size of a byte array that can be encrypted by using the specified asymmetric algoritm.

Parameters
algAsymmetric algorithm that would be used for encryption.
Returns

Referenced by IG.Crypto.CryptoManager.AppAsymExportKey(), IG.Crypto.CryptoManager.AppAsymKeyInfo(), and IG.Crypto.CryptoManager.AppCertInfo().

static bool IG.Crypto.UtilCrypto.AsymEncryptionDecryptionTest ( string  testString,
AsymmetricAlgorithm  algEnc,
AsymmetricAlgorithm  algDec = null 
)
inlinestatic

Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts the specified string.

Returns true if the test passes and false if not.

The specified string must be short enough.

Parameters
testStringString to be encrypted and decrypted.

Must be short enough in order to be suitable for asymmetric encryption / decryption.

If null or empty string then false is returned.

Parameters
algEncAsymmetric algorithm object used for encryption (and also for decryption if the second algorithm object is not specified).

If null then false is returned.

Parameters
algDecAsymmetric algorithm used for decryption.

If null then the first algorithm object is used for both encryption and decryption.

Possibility of having two algorithm objects makes possible to test situations when one object contains only the public key and a different object contains the private key.

Returns
True if the secified asymmetric algorithms correctly encrypt/decrypt the specified string, false otherwise.

Referenced by IG.Crypto.CryptoManager.AppAsymExportKey(), IG.Crypto.CryptoManager.AppAsymKeyInfo(), IG.Crypto.CryptoManager.AppAsymTest(), and IG.Crypto.CryptoManager.AppCertInfo().

static bool IG.Crypto.UtilCrypto.AsymEncryptionDecryptionTest ( string  testString,
out string  errorString,
AsymmetricAlgorithm  algEnc,
AsymmetricAlgorithm  algDec = null 
)
inlinestatic

Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts the specified string.

Returns true if the test passes and false if not.

The specified string must be short enough.

Parameters
testStringString to be encrypted and decrypted.

Must be short enough in order to be suitable for asymmetric encryption / decryption.

If null or empty string then false is returned.

Parameters
errorStringString variable where error message is stored, in case that exception is thrown during encryption/decryption. If no exception is thrown then the variable attains value null.
algEncAsymmetric algorithm object used for encryption (and also for decryption if the second algorithm object is not specified).

If null then false is returned.

Parameters
algDecAsymmetric algorithm used for decryption.

If null then the first algorithm object is used for both encryption and decryption.

Possibility of having two algorithm objects makes possible to test situations when one object contains only the public key and a different object contains the private key.

Returns
True if the secified asymmetric algorithms correctly encrypt/decrypt the specified string, false otherwise.
static bool IG.Crypto.UtilCrypto.AsymEncryptionDecryptionTest ( int  length,
AsymmetricAlgorithm  algEnc,
AsymmetricAlgorithm  algDec = null 
)
inlinestatic

Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts a random byte array of the specified size.

Returns true if the test passes (encrypted and then decrypted bytes equal to original) and false if not.

The specified length must me smaller and equal to the value returned by GetMaximalAsymmetricTextLength for the test to pass (beside the encryption/decryption capability and correctness of operaton).

Parameters
lengthLength of the random byte array that is encrypted / decrypted.
algEncAsymmetric algorithm object used for encryption (and also for decryption if the second algorithm object is not specified).

If null then false is returned.

Parameters
algDecAsymmetric algorithm used for decryption.

If null then the first algorithm object is used for both encryption and decryption.

Possibility of having two algorithm objects makes possible to test situations when one object contains only the public key and a different object contains the private key.

Returns
True if the secified asymmetric algorithms correctly encrypt/decrypt a random byte array of the specified length, false otherwise.
static bool IG.Crypto.UtilCrypto.AsymEncryptionDecryptionTest ( int  length,
out string  errorString,
AsymmetricAlgorithm  algEnc,
AsymmetricAlgorithm  algDec = null 
)
inlinestatic

Tests whether the specified asymmetric algorithm(s) correctly encrypts/decrypts a random byte array of the specified size.

Returns true if the test passes (encrypted and then decrypted bytes equal to original) and false if not.

The specified length must me smaller and equal to the value returned by GetMaximalAsymmetricTextLength for the test to pass (beside the encryption/decryption capability and correctness of operaton).

Parameters
lengthLength of the random byte array to be encrypted and decrypted.

Must be short enough in order to be suitable for asymmetric encryption / decryption. Maximal length can be obtained by the GetMaximalAsymmetricTextLength method.

If null or empty string then false is returned.

Parameters
errorStringString variable where error message is stored, in case that exception is thrown during encryption/decryption. If no exception is thrown then the variable attains value null.
algEncAsymmetric algorithm object used for encryption (and also for decryption if the second algorithm object is not specified).

If null then false is returned.

Parameters
algDecAsymmetric algorithm used for decryption.

If null then the first algorithm object is used for both encryption and decryption.

Possibility of having two algorithm objects makes possible to test situations when one object contains only the public key and a different object contains the private key.

Returns
True if the secified asymmetric algorithms correctly encrypt/decrypt a random byte array of the specified length, false otherwise.
static AsymmetricAlgorithm IG.Crypto.UtilCrypto.GetAsymmetricAlgorithm ( AsymmetricAlgorithmType  algorithmType,
string  containerName = null,
string  xmlString = null,
CspProviderFlags  flags = CspProviderFlags.NoFlags,
string  certificateFilePath = null,
string  certificateName = null,
string  certStore = null 
)
inlinestatic

Creates (if necessary) and returns a new asymmetric algorithm whose keys are either created or obtained through arguments.

Parameters
algorithmTypeType of the asymmetric algorithm that is returned.
containerNameName of the key container where the keys persist. If not specified then keys are not persistent.
xmlStringIf not null, this string must contain properly formed XML form which the keys are read.
flagsFlags of type CspProviderFlags used in crypto service parameters when algorithm object is created. If the value is CspProviderFlags.NoFlags then flags are not used.
certificateFilePathName of the certificate file from which algorithm keys are obtained.
certificateNameName of the certificate from one of the standard certificate stores from which the algorithm keys are obtained.
certStoreCertificate store from which certificate named certificateName is obtained. If null then all standard stores are searched for.

References IG.Crypto.UtilCrypto.AsymmetricAlgorithmTypeToString().

Referenced by IG.Crypto.CryptoManager.AppAsymTest(), and IG.Crypto.CryptoManager.ResolveAsymParameters().

static void IG.Crypto.UtilCrypto.DeleteKeyInCsp ( AsymmetricAlgorithmType  algorithmType,
string  containerName 
)
inlinestatic

Deletes the asymmetric algorithm keys from the specified key container.

Parameters
algorithmTypeType of the asymmetric algorithm for which the keys are deleted.
containerNameName of the container from which keys are deleted.

References IG.Crypto.UtilCrypto.AsymmetricAlgorithmTypeToString().

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

static void IG.Crypto.UtilCrypto.PrepareAymmetricAllgorithmBasic ( AsymmetricAlgorithmType  algorithmType,
ref AsymmetricAlgorithm  algorithm,
string  containerName = null,
string  xmlString = null,
CspProviderFlags  flags = CspProviderFlags.NoFlags,
bool  useLargestKey = false 
)
inlinestatic
static string IG.Crypto.UtilCrypto.EncryptStringAsymShort ( string  stringToEncrypt,
AsymmetricAlgorithm  algorithm,
AsymmetricAlgorithmType  algorithmType = AsymmetricAlgorithmType.None 
)
inlinestatic
static string IG.Crypto.UtilCrypto.DecryptStringAsymShort ( string  cipherText,
AsymmetricAlgorithm  algorithm,
AsymmetricAlgorithmType  algorithmType = AsymmetricAlgorithmType.None 
)
inlinestatic
static byte [] IG.Crypto.UtilCrypto.EncryptAsymShort ( byte[]  originalBytes,
AsymmetricAlgorithm  algorithm,
AsymmetricAlgorithmType  algorithmType = AsymmetricAlgorithmType.None 
)
inlinestatic
static byte [] IG.Crypto.UtilCrypto.DecryptAsymShort ( byte[]  originalBytes,
AsymmetricAlgorithm  algorithm,
AsymmetricAlgorithmType  algorithmType = AsymmetricAlgorithmType.None 
)
inlinestatic
static byte [] IG.Crypto.UtilCrypto.EncryptAsymShort ( byte[]  originalBytes,
AsymmetricAlgorithmType  algorithmType = AsymmetricAlgorithmType.None,
AsymmetricAlgorithm  algorithm = null,
string  containerName = null,
string  xmlString = null,
CspProviderFlags  flags = CspProviderFlags.NoFlags,
bool  useLargestKey = false 
)
inlinestatic
static byte [] IG.Crypto.UtilCrypto.DecryptAsymShort ( byte[]  originalBytes,
AsymmetricAlgorithmType  algorithmType = AsymmetricAlgorithmType.None,
AsymmetricAlgorithm  algorithm = null,
string  containerName = null,
string  xmlString = null,
CspProviderFlags  flags = CspProviderFlags.NoFlags,
bool  useLargestKey = false 
)
inlinestatic
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.

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
bool IG.Crypto.UtilCrypto._isUsed_fOAEP1 = false
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.

Read-only, safely provided on demand (using Util.LockGlobal when created).

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.

bool IG.Crypto.UtilCrypto.IsUsed_fOAEP
staticget

Whether to perform direct RSA encryption using OAEP (optimal asymmetric encryption padding - only available on computers running MS Windows XP or later).

To do:

Check whether this works in Mono.


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