/// <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)); }
/// <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; }
/// <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); } }
/// <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);
/// <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);
/// <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); }