本文整理汇总了C#中System.Security.Cryptography.HashAlgorithm.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm.GetType方法的具体用法?C# HashAlgorithm.GetType怎么用?C# HashAlgorithm.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.HashAlgorithm
的用法示例。
在下文中一共展示了HashAlgorithm.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HashEncryptor
/// <summary>
/// 지정된 HashAlgorithm을 이용하는 HashEncryptor를 생성합니다.
/// </summary>
/// <param name="algorithm"></param>
public HashEncryptor(HashAlgorithm algorithm) {
algorithm.ShouldNotBeNull("algorithm");
Algorithm = algorithm;
if(IsDebugEnabled)
log.Debug("Hash 계산을 위해 HashEncryptor를 생성합니다... Algorithm=[{0}]", algorithm.GetType().FullName);
}
示例2: Get
public static string Get(HashAlgorithm algo)
{
if (algo is SHA1)
return "SHA1";
if (algo is SHA256)
return "SHA256";
if (algo is SHA384)
return "SHA384";
if (algo is SHA512)
return "SHA512";
if (algo is MD5)
return "MD5";
if (algo is RIPEMD160)
return "RIPEMD160";
throw new UnknownAlgorithmException("uncatched algorithm " + algo.GetType());
}
示例3: map_hash_algorithm
// Map a HashAlgorithm object to our HASH_ALGORITHM enumeration
HASH_ALGORITHM map_hash_algorithm(HashAlgorithm hasher)
{
Type t = hasher.GetType();
if (Object.ReferenceEquals(t, typeof(MD5CryptoServiceProvider)))
return HASH_ALGORITHM.RSA_MD5;
if (Object.ReferenceEquals(t, typeof(SHA1CryptoServiceProvider)))
return HASH_ALGORITHM.RSA_SHA1;
throw new ArgumentException("unknown HashAlgorithm");
}
示例4: GenerateHash
/// <summary>
/// Get the hash value of the assembly when hashed with a specific algorithm. The actual hash
/// algorithm object is not used, however the same type of object will be used.
/// </summary>
public byte[] GenerateHash(HashAlgorithm hashAlg)
{
if (hashAlg == null)
throw new ArgumentNullException("hashAlg");
Contract.EndContractBlock();
byte[] hashValue = GenerateHash(hashAlg.GetType());
byte[] returnHash = new byte[hashValue.Length];
Array.Copy(hashValue, returnHash, returnHash.Length);
return returnHash;
}
示例5: GenerateHash
public byte[] GenerateHash(HashAlgorithm hashAlg)
{
if (hashAlg == null)
{
throw new ArgumentNullException("hashAlg");
}
byte[] sourceArray = this.GenerateHash(hashAlg.GetType());
byte[] destinationArray = new byte[sourceArray.Length];
Array.Copy(sourceArray, destinationArray, destinationArray.Length);
return destinationArray;
}
示例6: Hash
static HashResult Hash(byte[] text, byte[] salt, HashAlgorithm algorithm)
{
if (text == null || text.Length == 0)
return null;
if (salt == null || salt.Length < SALT_LENGTH)
throw new ArgumentException("Must be atleast " + SALT_LENGTH.ToString() + " characters in length", "salt");
// Het hashingalgoritme verwacht bytes. Converteer onze string naar bytes
var bytesUnhashed = text.Concat(salt).ToArray();
// Magic time
var hash = algorithm.ComputeHash(bytesUnhashed);
// Transformeer de salt en de hash naar een Base-64 encoded string zodat je deze gemakkelijk kan opslaan en opsturen
return new HashResult(algorithm.GetType().Name, Convert.ToBase64String(salt), Convert.ToBase64String(hash));
}
示例7: TestHash
private static void TestHash(HashAlgorithm hashAlgorithm, int count, int size)
{
// Create test string of relevant length.
Random random = new Random();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < count; i++)
{
StringBuilder sb = new StringBuilder();
for (int a = 0; a < size; a++)
sb.Append(CharacterPool[(int) (random.NextDouble() * CharacterPool.Length)]);
string testString = sb.ToString();
GetHash(hashAlgorithm, testString);
}
stopwatch.Stop();
Trace.WriteLine(
string.Format(
"{1}ms\t{2} chars x {3}\t{0}",
hashAlgorithm.GetType(),
stopwatch.ElapsedTicks * 1000 / Stopwatch.Frequency,
size,
count));
}
示例8: LogVerifySignedInfo
internal static void LogVerifySignedInfo(SignedXml signedXml, AsymmetricAlgorithm key, SignatureDescription signatureDescription, HashAlgorithm hashAlgorithm, AsymmetricSignatureDeformatter asymmetricSignatureDeformatter, byte[] actualHashValue, byte[] signatureValue)
{
if (InformationLoggingEnabled)
{
string data = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_VerifySignedInfoAsymmetric"), new object[] { GetKeyName(key), signatureDescription.GetType().Name, hashAlgorithm.GetType().Name, asymmetricSignatureDeformatter.GetType().Name });
WriteLine(signedXml, TraceEventType.Information, SignedXmlDebugEvent.VerifySignedInfo, data);
}
if (VerboseLoggingEnabled)
{
string str2 = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_ActualHashValue"), new object[] { FormatBytes(actualHashValue) });
WriteLine(signedXml, TraceEventType.Verbose, SignedXmlDebugEvent.VerifySignedInfo, str2);
string str3 = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_RawSignatureValue"), new object[] { FormatBytes(signatureValue) });
WriteLine(signedXml, TraceEventType.Verbose, SignedXmlDebugEvent.VerifySignedInfo, str3);
}
}
示例9: LogSigning
internal static void LogSigning(SignedXml signedXml, object key, SignatureDescription signatureDescription, HashAlgorithm hash, AsymmetricSignatureFormatter asymmetricSignatureFormatter)
{
if (InformationLoggingEnabled)
{
string data = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_SigningAsymmetric"), new object[] { GetKeyName(key), signatureDescription.GetType().Name, hash.GetType().Name, asymmetricSignatureFormatter.GetType().Name });
WriteLine(signedXml, TraceEventType.Information, SignedXmlDebugEvent.Signing, data);
}
}