本文整理汇总了C#中HashAlgorithmName类的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithmName类的具体用法?C# HashAlgorithmName怎么用?C# HashAlgorithmName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashAlgorithmName类属于命名空间,在下文中一共展示了HashAlgorithmName类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:dotnet,项目名称:corefx,代码行数:20,代码来源:IncrementalHash.net46.cs
示例2: SignData
public virtual byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)
{
if (data == null)
throw new ArgumentNullException("data");
return SignData(data, 0, data.Length, hashAlgorithm);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:ECDsa.cs
示例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);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:ECDsa.cs
示例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);
}
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:DSA.cs
示例5: VerifyIncrementalHash
public static void VerifyIncrementalHash(HashAlgorithm referenceAlgorithm, HashAlgorithmName hashAlgorithm)
{
using (referenceAlgorithm)
using (IncrementalHash incrementalHash = IncrementalHash.CreateHash(hashAlgorithm))
{
VerifyIncrementalResult(referenceAlgorithm, incrementalHash);
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:IncrementalHashTests.cs
示例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();
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:18,代码来源:ECDiffieHellman.cs
示例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;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:IncrementalHash.net46.cs
示例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);
}
开发者ID:jmhardison,项目名称:corefx,代码行数:9,代码来源:RSA.cs
示例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);
}
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:DSA.cs
示例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);
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:9,代码来源:ECDsa.cs
示例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);
}
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:IncrementalHashTests.cs
示例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;
}
开发者ID:nuskarthik,项目名称:corefx,代码行数:10,代码来源:RSACng.HashData.cs
示例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!");
}
开发者ID:huamanhtuyen,项目名称:TagLo1,代码行数:11,代码来源:CryptographyHelper.cs
示例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);
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:14,代码来源:RsaCngTests.cs
示例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() };
}
}
开发者ID:leevox,项目名称:sdk,代码行数:15,代码来源:HasherAdapter.cs
示例16: CreateHMAC
internal static IncrementalHash CreateHMAC(HashAlgorithmName hashAlgorithmName, byte[] key)
{
switch (hashAlgorithmName)
{
default:
case HashAlgorithmName.SHA1:
return new IncrementalHash{ HashAlgorithm = new HMACSHA1(key) };
case HashAlgorithmName.SHA256:
return new IncrementalHash{ HashAlgorithm = new HMACSHA256(key) };
case HashAlgorithmName.SHA512:
return new IncrementalHash{ HashAlgorithm = new HMACSHA512(key) };
case HashAlgorithmName.MD5:
return new IncrementalHash{ HashAlgorithm = new HMACMD5(key) };
}
}
开发者ID:leevox,项目名称:sdk,代码行数:15,代码来源:HasherAdapter.cs
示例17: VerifyData
public virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm)
{
if (data == null)
throw new ArgumentNullException(nameof(data));
if (offset < 0 || offset > data.Length)
throw new ArgumentOutOfRangeException(nameof(offset));
if (count < 0 || count > data.Length - offset)
throw new ArgumentOutOfRangeException(nameof(count));
if (signature == null)
throw new ArgumentNullException(nameof(signature));
if (string.IsNullOrEmpty(hashAlgorithm.Name))
throw new ArgumentException(SR.Cryptography_HashAlgorithmNameNullOrEmpty, nameof(hashAlgorithm));
byte[] hash = HashData(data, offset, count, hashAlgorithm);
return VerifyHash(hash, signature);
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:16,代码来源:ECDsa.cs
示例18: SignHash
public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
{
if (hashAlgorithm != HashAlgorithmName.SHA256)
{
throw new ArgumentException(
$"Unsupported HashAlgorithmName '{hashAlgorithm}', only SHA256 supported.", nameof(hashAlgorithm));
}
if (padding != RSASignaturePadding.Pkcs1)
{
throw new ArgumentException(
$"Unsupported RSASignaturePadding '{padding}', only Pkcs1 supported.", nameof(padding));
}
var signer = new RsaDigestSigner(new NullDigest(), NistObjectIdentifiers.IdSha256);
signer.Init(true, _parameters);
signer.BlockUpdate(hash, 0, hash.Length);
return signer.GenerateSignature();
}
开发者ID:LindaLawton,项目名称:google-api-dotnet-client,代码行数:17,代码来源:RsaStandard.cs
示例19: GetHashAlgorithm
/// <summary>
/// Get HashAlgorithm with specify name
/// </summary>
/// <param name="name">name of hash algorithm</param>
/// <returns></returns>
private HashAlgorithm GetHashAlgorithm(HashAlgorithmName name)
{
switch (name)
{
case HashAlgorithmName.MD5:
return new MD5CryptoServiceProvider();
case HashAlgorithmName.SHA1:
return new SHA1Managed();
case HashAlgorithmName.SHA256:
return new SHA256Managed();
case HashAlgorithmName.SHA384:
return new SHA384Managed();
case HashAlgorithmName.SHA512:
return new SHA512Managed();
}
throw new CryptographicException("Unknown hash algorithm!");
}
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:22,代码来源:RSACryptography.cs
示例20: RsaPkcs15_Sign
/// <summary>
/// Creates an RSA PKCS#1 v1.5 signature of a hash algorithm for the stream.
/// </summary>
private static byte[] RsaPkcs15_Sign(
ArraySegment<byte> dataToSign,
X509Certificate2 signingCertificate,
HashAlgorithmName algorithm)
{
// extract the private key.
using (RSA rsa = signingCertificate.GetRSAPrivateKey())
{
if (rsa == null)
{
throw ServiceResultException.Create(StatusCodes.BadSecurityChecksFailed, "No private key for certificate.");
}
// create the signature.
return rsa.SignData(dataToSign.Array, dataToSign.Offset, dataToSign.Count, algorithm, RSASignaturePadding.Pkcs1);
}
}
开发者ID:OPCFoundation,项目名称:UA-.NETStandardLibrary,代码行数:20,代码来源:TcpChannel.Rsa.cs
注:本文中的HashAlgorithmName类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论