Example #1
0
        /// <summary>
        /// Hash a file using a Unix-like format with the provided Crypt Alghoritm type and a salt
        /// </summary>
        /// <param name="sourceFile">The file to hash complete path</param>
        /// <param name="salt">The salt to apply to the hash</param>
        /// <param name="unixCryptType">The Crypt Alghoritm type</param>
        /// <returns>The hash</returns>
        public string HashFile(string sourceFile, string salt, UnixCryptTypes unixCryptType)
        {
            if (sourceFile.IsNullOrWhiteSpace() || !File.Exists(sourceFile))
            {
                throw new FileNotFoundException("Cannot find the specified source file", sourceFile ?? "null");
            }

            var text = File.ReadAllText(sourceFile);

            return(HashString(text, salt, unixCryptType));
        }
Example #2
0
        /// <summary>
        /// Hash a string using a Unix-like format with the provided Crypt Alghoritm type and a salt
        /// </summary>
        /// <param name="sourceString">The string to hash</param>
        /// <param name="salt">The salt to apply to the hash</param>
        /// <param name="unixCryptType">The Crypt Alghoritm type</param>
        /// <returns>The hash</returns>
        public string HashString(string sourceString, string salt, UnixCryptTypes unixCryptType)
        {
            if (string.IsNullOrEmpty(salt))
                throw new ArgumentException("Please specify the salt", nameof(salt));

            if (sourceString != null)
            {
                salt = "$" + (int)unixCryptType + "$" + salt;
                return UnixCryptAlg.CryptUtils.Crypt(sourceString, salt);
            }
            else
                return String.Empty;
        }
Example #3
0
        /// <summary>
        /// Hash a string using a Unix-like format with the provided Crypt Alghoritm type and a salt
        /// </summary>
        /// <param name="sourceString">The string to hash</param>
        /// <param name="salt">The salt to apply to the hash</param>
        /// <param name="unixCryptType">The Crypt Alghoritm type</param>
        /// <returns>The hash</returns>
        public string HashString(string sourceString, string salt, UnixCryptTypes unixCryptType)
        {
            if (string.IsNullOrEmpty(salt))
            {
                throw new ArgumentException("Please specify the salt", nameof(salt));
            }

            if (sourceString != null)
            {
                salt = "$" + (int)unixCryptType + "$" + salt;
                return(UnixCryptAlg.CryptUtils.Crypt(sourceString, salt));
            }
            else
            {
                return(String.Empty);
            }
        }
Example #4
0
 /// <summary>
 /// Hash a file using a Unix-like format with the provided Crypt Alghoritm type
 /// </summary>
 /// <param name="sourceFile">The file to hash complete path</param>        
 /// <param name="unixCryptType">The Crypt Alghoritm type</param>
 /// <returns>The hash</returns>
 public string HashFile(string sourceFile, UnixCryptTypes unixCryptType)
     => HashFile(sourceFile, generateSalt(), unixCryptType);        
Example #5
0
 /// <summary>
 /// Hash a string using a Unix-like format with the provided Crypt Alghoritm type
 /// </summary>
 /// <param name="sourceString">The string to hash</param>
 /// <param name="unixCryptType">The Crypt Alghoritm type</param>
 /// <returns>The hash</returns>
 public string HashString(string sourceString, UnixCryptTypes unixCryptType)
     => HashString(sourceString, generateSalt(), unixCryptType);        
Example #6
0
        /// <summary>
        /// Hash a file using a Unix-like format with the provided Crypt Alghoritm type and a salt
        /// </summary>
        /// <param name="sourceFile">The file to hash complete path</param>
        /// <param name="salt">The salt to apply to the hash</param>
        /// <param name="unixCryptType">The Crypt Alghoritm type</param>
        /// <returns>The hash</returns>
        public string HashFile(string sourceFile, string salt, UnixCryptTypes unixCryptType)
        {
            if (sourceFile.IsNullOrWhiteSpace() || !File.Exists(sourceFile))
                throw new FileNotFoundException("Cannot find the specified source file", sourceFile ?? "null");

            var text = File.ReadAllText(sourceFile);

            return HashString(text, salt, unixCryptType);
        }
Example #7
0
 /// <summary>
 /// Hash a file using a Unix-like format with the provided Crypt Alghoritm type
 /// </summary>
 /// <param name="sourceFile">The file to hash complete path</param>
 /// <param name="unixCryptType">The Crypt Alghoritm type</param>
 /// <returns>The hash</returns>
 public string HashFile(string sourceFile, UnixCryptTypes unixCryptType)
 => HashFile(sourceFile, generateSalt(), unixCryptType);
Example #8
0
 /// <summary>
 /// Hash a string using a Unix-like format with the provided Crypt Alghoritm type
 /// </summary>
 /// <param name="sourceString">The string to hash</param>
 /// <param name="unixCryptType">The Crypt Alghoritm type</param>
 /// <returns>The hash</returns>
 public string HashString(string sourceString, UnixCryptTypes unixCryptType)
 => HashString(sourceString, generateSalt(), unixCryptType);