using System.IO;
namespace System.Security.Cryptography {
#pragma warning disable CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente
public static class HashAlgorithm_CB_Extension {
#pragma warning restore CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente
///
/// Computes the hash value for the specified byte array.
///
/// Target object.
/// The full path of the file.
///
///
///
///
///
///
///
///
///
///
/// The computed hash code.
public static byte[] ComputeHash(this HashAlgorithm H, string FilePath)
=> H.ComputeHash(File.ReadAllBytes(FilePath));
///
/// Computes the hash value for the specified byte array.
///
/// Target object.
/// The full path of the file.
///
///
///
///
///
///
///
///
///
///
/// The computed hash code for string.
public static HashString ComputeHashToString(this HashAlgorithm H, string FilePath) {
byte[] bytes = ComputeHash(H, FilePath);
if (!(bytes is null))
return new HashString(bytes);
return HashString.Empty;
}
///
/// Computes the hash value for the specified byte array.
///
/// Target object.
/// The input to compute the hash code for.
///
///
/// The computed hash code for string.
public static HashString ComputeHashToString(this HashAlgorithm H, byte[] buffer) {
buffer = H.ComputeHash(buffer);
if (!(buffer is null))
return new HashString(buffer);
return HashString.Empty;
}
///
/// Computes the hash value for the specified region of the specified byte array.
///
/// Target object.
/// The input to compute the hash code for.
/// The offset into the byte array from which to begin using data.
/// The number of bytes in the array to use as data.
///
///
///
///
/// The computed hash code for string.
public static HashString ComputeHashToString(this HashAlgorithm H, byte[] buffer, int offset, int count) {
buffer = H.ComputeHash(buffer, offset, count);
if (!(buffer is null))
return new HashString(buffer);
return HashString.Empty;
}
///
/// Computes the hash value for the specified object.
///
/// Target object.
/// The input to compute the hash code for.
///
/// The computed hash code for string.
public static HashString ComputeHashToString(this HashAlgorithm H, Stream inputStream) {
byte[] buffer = H.ComputeHash(inputStream);
if (!(buffer is null))
return new HashString(buffer);
return HashString.Empty;
}
}
}