本文整理汇总了C#中HashAlgorithmName类的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithmName类的具体用法?C# HashAlgorithmName怎么用?C# HashAlgorithmName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashAlgorithmName类属于命名空间,在下文中一共展示了HashAlgorithmName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateHash
/// <summary>
/// Create an <see cref="IncrementalHash"/> for the algorithm specified by <paramref name="hashAlgorithm"/>.
/// </summary>
/// <param name="hashAlgorithm">The name of the hash algorithm to perform.</param>
/// <returns>
/// An <see cref="IncrementalHash"/> instance ready to compute the hash algorithm specified
/// by <paramref name="hashAlgorithm"/>.
/// </returns>
/// <exception cref="ArgumentException">
/// <paramref name="hashAlgorithm"/>.<see cref="HashAlgorithmName.Name"/> is <c>null</c>, or
/// the empty string.
/// </exception>
/// <exception cref="CryptographicException"><paramref name="hashAlgorithm"/> is not a known hash algorithm.</exception>
public static IncrementalHash CreateHash(HashAlgorithmName hashAlgorithm)
{
if (string.IsNullOrEmpty(hashAlgorithm.Name))
throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
return new IncrementalHash(hashAlgorithm, GetHashAlgorithm(hashAlgorithm));
}
示例2: SignData
public virtual byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)
{
if (data == null)
throw new ArgumentNullException("data");
return SignData(data, 0, data.Length, hashAlgorithm);
}
示例3: VerifyData
public bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm)
{
if (data == null)
throw new ArgumentNullException("data");
return VerifyData(data, 0, data.Length, signature, hashAlgorithm);
}
示例4: SignData
public virtual byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm)
{
if (data == null) { throw new ArgumentNullException(nameof(data)); }
if (String.IsNullOrEmpty(hashAlgorithm.Name)) { throw HashAlgorithmNameNullOrEmpty(); }
byte[] hash = HashData(data, hashAlgorithm);
return CreateSignature(hash);
}
示例5: VerifyIncrementalHash
public static void VerifyIncrementalHash(HashAlgorithm referenceAlgorithm, HashAlgorithmName hashAlgorithm)
{
using (referenceAlgorithm)
using (IncrementalHash incrementalHash = IncrementalHash.CreateHash(hashAlgorithm))
{
VerifyIncrementalResult(referenceAlgorithm, incrementalHash);
}
}
示例6: DeriveKeyFromHash
/// <summary>
/// Derive key material using the formula HASH(secretPrepend || x || secretAppend) where x is the computed
/// result of the EC Diffie-Hellman algorithm.
/// </summary>
/// <param name="otherPartyPublicKey">The public key of the party with which to derive a mutual secret.</param>
/// <param name="hashAlgorithm">The identifier for the hash algorithm to use.</param>
/// <param name="secretPrepend">A value to prepend to the derived secret before hashing. A <c>null</c> value is treated as an empty array.</param>
/// <param name="secretAppend">A value to append to the derived secret before hashing. A <c>null</c> value is treated as an empty array.</param>
/// <returns>A hashed output suitable for key material</returns>
/// <exception cref="ArgumentException"><paramref name="otherPartyPublicKey"/> is over a different curve than this key</exception>
public virtual byte[] DeriveKeyFromHash(
ECDiffieHellmanPublicKey otherPartyPublicKey,
HashAlgorithmName hashAlgorithm,
byte[] secretPrepend,
byte[] secretAppend)
{
throw DerivedClassMustOverride();
}
示例7: IncrementalHash
private IncrementalHash(HashAlgorithmName name, HashAlgorithm hash)
{
Debug.Assert(name != null);
Debug.Assert(!string.IsNullOrEmpty(name.Name));
Debug.Assert(hash != null);
_algorithmName = name;
_hash = hash;
}
示例8: SignData
public byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
return SignData(data, 0, data.Length, hashAlgorithm, padding);
}
示例9: VerifyData
public virtual bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm)
{
if (data == null) { throw new ArgumentNullException(nameof(data)); }
if (signature == null) { throw new ArgumentNullException(nameof(signature)); }
if (String.IsNullOrEmpty(hashAlgorithm.Name)) { throw HashAlgorithmNameNullOrEmpty(); }
byte[] hash = HashData(data, hashAlgorithm);
return VerifySignature(hash, signature);
}
示例10: SignData
public virtual byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) {
if (data == null) { throw new ArgumentNullException("data"); }
if (offset < 0 || offset > data.Length) { throw new ArgumentOutOfRangeException("offset"); }
if (count < 0 || count > data.Length - offset) { throw new ArgumentOutOfRangeException("count"); }
if (String.IsNullOrEmpty(hashAlgorithm.Name)) { throw HashAlgorithmNameNullOrEmpty(); }
byte[] hash = HashData(data, offset, count, hashAlgorithm);
return SignHash(hash);
}
示例11: VerifyIncrementalHMAC
public static void VerifyIncrementalHMAC(HMAC referenceAlgorithm, HashAlgorithmName hashAlgorithm)
{
using (referenceAlgorithm)
using (IncrementalHash incrementalHash = IncrementalHash.CreateHMAC(hashAlgorithm, s_hmacKey))
{
referenceAlgorithm.Key = s_hmacKey;
VerifyIncrementalResult(referenceAlgorithm, incrementalHash);
}
}
示例12: HashData
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
{
// We're sealed and the base should have checked these already.
Debug.Assert(data != null);
Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name));
HashAlgorithm hasher = GetHasher(hashAlgorithm);
byte[] hash = hasher.ComputeHash(data);
return hash;
}
示例13: GetHashAlgorithm
public static HashAlgorithm GetHashAlgorithm(HashAlgorithmName name)
{
switch (name)
{
case HashAlgorithmName.MD5:
return new MD5CryptoServiceProvider();
case HashAlgorithmName.SHA1:
return new SHA1Managed();
}
throw new Exception("Unknown hash algorithm!");
}
示例14: TestSignVerifyDataRoundTrip
private static void TestSignVerifyDataRoundTrip(byte[] message, HashAlgorithmName hashAlgorithm, RSASignaturePadding paddingMode, int expectedSignatureLength)
{
using (RSA rsa = new RSACng())
{
byte[] signature = rsa.SignData(message, hashAlgorithm, paddingMode);
// RSACng.SignHash() is intentionally non-deterministic so we can verify that we got back a signature of the right length
// but nothing about the contents.
Assert.Equal(expectedSignatureLength, signature.Length);
bool verified = rsa.VerifyData(message, signature, hashAlgorithm, paddingMode);
Assert.True(verified);
}
}
示例15: CreateHash
internal static IncrementalHash CreateHash(HashAlgorithmName hashAlgorithmName)
{
switch (hashAlgorithmName)
{
default:
case HashAlgorithmName.SHA1:
return new IncrementalHash{ HashAlgorithm = SHA1.Create() };
case HashAlgorithmName.SHA256:
return new IncrementalHash{ HashAlgorithm = SHA256.Create() };
case HashAlgorithmName.SHA512:
return new IncrementalHash{ HashAlgorithm = SHA512.Create() };
case HashAlgorithmName.MD5:
return new IncrementalHash{ HashAlgorithm = MD5.Create() };
}
}