本文整理汇总了C#中HashAlgorithm类的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm类的具体用法?C# HashAlgorithm怎么用?C# HashAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashAlgorithm类属于命名空间,在下文中一共展示了HashAlgorithm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WinDbFiller
public WinDbFiller(IFingerprintService fingerprintService, IWorkUnitBuilder workUnitBuilder, ITagService tagService)
{
this.fingerprintService = fingerprintService;
this.workUnitBuilder = workUnitBuilder;
this.tagService = tagService;
InitializeComponent();
Icon = Resources.Sound;
foreach (object item in ConfigurationManager.ConnectionStrings)
{
_cmbDBFillerConnectionString.Items.Add(item.ToString());
}
if (_cmbDBFillerConnectionString.Items.Count > 0)
{
_cmbDBFillerConnectionString.SelectedIndex = 0;
}
_btnStart.Enabled = false;
_btnStop.Enabled = false;
_nudThreads.Value = MaxThreadToProcessFiles;
_pbTotalSongs.Visible = false;
hashAlgorithm = 0; /**/
_lbAlgorithm.SelectedIndex = 0; /*Set default algorithm LSH*/
if (hashAlgorithm == HashAlgorithm.LSH)
{
_nudHashKeys.ReadOnly = false;
_nudHashTables.ReadOnly = false;
}
object[] items = Enum.GetNames(typeof (StrideType)); /*Add enumeration types in the combo box*/
_cmbStrideType.Items.AddRange(items);
_cmbStrideType.SelectedIndex = 0;
}
开发者ID:eugentorica,项目名称:soundfingerprinting,代码行数:34,代码来源:WinDBFiller.cs
示例2: WinDBFiller
/// <summary>
/// Constructor
/// </summary>
public WinDBFiller()
{
InitializeComponent();
Icon = Resources.Sound;
foreach (object item in ConfigurationManager.ConnectionStrings) /*Detect all the connection strings*/
_cmbDBFillerConnectionString.Items.Add(item.ToString());
if (_cmbDBFillerConnectionString.Items.Count > 0)
_cmbDBFillerConnectionString.SelectedIndex = 0;
_btnStart.Enabled = false;
_btnStop.Enabled = false;
_nudThreads.Value = THREADS;
_pbTotalSongs.Visible = false;
_hashAlgorithm = 0; /**/
_lbAlgorithm.SelectedIndex = 0; /*Set default algorithm LSH*/
if (_hashAlgorithm == HashAlgorithm.LSH)
{
_nudHashKeys.ReadOnly = false;
_nudHashTables.ReadOnly = false;
}
string[] items = Enum.GetNames(typeof (StrideType)); /*Add enumeration types in the combo box*/
_cmbStrideType.Items.AddRange(items);
_cmbStrideType.SelectedIndex = 0;
}
开发者ID:gvillarroel,项目名称:memoria,代码行数:30,代码来源:WinDBFiller.cs
示例3: Main
static void Main(string[] args)
{
if (args.Length == 0 || args.Length > 1) {
Console.WriteLine("\r\nUsage: hash [filename]");
return;
}
HashAlgorithm[] hashes = new HashAlgorithm[] {
new MD2CryptoServiceProvider(), new MD5CryptoServiceProvider(),
new SHA1CryptoServiceProvider(), new Org.Mentalis.Security.Cryptography.RIPEMD160Managed()
};
string[] names = new string[] {"MD2: ", "MD5: ", "SHA1: ", "RIPEMD160: "};
byte[] buffer = new byte[4096];
FileStream fs = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read);
int size = fs.Read(buffer, 0, buffer.Length);
while(size > 0) {
for(int i = 0; i < hashes.Length; i++) {
hashes[i].TransformBlock(buffer, 0, size, buffer, 0);
}
size = fs.Read(buffer, 0, buffer.Length);
}
for(int i = 0; i < hashes.Length; i++) {
hashes[i].TransformFinalBlock(buffer, 0, 0);
Console.WriteLine(names[i] + BytesToHex(hashes[i].Hash));
hashes[i].Clear();
}
fs.Close();
}
开发者ID:maikgreubel,项目名称:securitylibrary,代码行数:27,代码来源:Hash.cs
示例4: GetKeyUri
/// <summary>Build a URI for secret key provisioning.</summary>
/// <param name="algorithm">The hashing algorithm for the HMAC computation.</param>
/// <param name="issuer">The name of the entity issuing and maintaining the key.</param>
/// <param name="account">The account name for which the one-time codes will work.</param>
/// <param name="secret">The ASCII-encoded base32-encoded shared secret.</param>
/// <param name="period">The period step for the HMAC counter computation.</param>
/// <param name="digits">The number of digits of the one-time codes.</param>
/// <returns>The provisioning URI.</returns>
public static string GetKeyUri(
HashAlgorithm algorithm,
string issuer,
string account,
byte[] secret,
int digits = Otp.DefaultDigits,
int period = Totp.DefaultPeriod)
{
Contract.Requires<ArgumentOutOfRangeException>(Enum.IsDefined(typeof(HashAlgorithm), algorithm));
Contract.Requires<ArgumentOutOfRangeException>(algorithm != HashAlgorithm.Unknown);
Contract.Requires<ArgumentNullException>(issuer != null);
Contract.Requires<ArgumentOutOfRangeException>(!string.IsNullOrWhiteSpace(issuer));
Contract.Requires<ArgumentNullException>(account != null);
Contract.Requires<ArgumentOutOfRangeException>(!string.IsNullOrWhiteSpace(account));
Contract.Requires<ArgumentNullException>(secret != null);
Contract.Requires<ArgumentException>(secret.Length > 0);
Contract.Requires<ArgumentOutOfRangeException>(digits > 0);
Contract.Requires<ArgumentOutOfRangeException>(period > 0);
Contract.Ensures(!string.IsNullOrWhiteSpace(Contract.Result<string>()));
return
Otp.GetKeyUri(
OtpType.Totp,
issuer,
account,
secret,
algorithm,
digits,
0,
period);
}
开发者ID:kappa7194,项目名称:otp,代码行数:39,代码来源:Totp.cs
示例5: GetCode
internal static int GetCode(
HashAlgorithm algorithm,
string secret,
long counter,
int digits)
{
MacAlgorithmProvider algorithmProvider = MacAlgorithmProvider.OpenAlgorithm(algorithm.ToAlgorithmName());
var keyMaterial = CryptographicBuffer.ConvertStringToBinary(secret, BinaryStringEncoding.Utf8);
var key = algorithmProvider.CreateKey(keyMaterial);
var hash = CryptographicEngine.Sign(key, CounterToBytes(counter).AsBuffer());
byte[] hashArray = new byte[hash.Length];
CryptographicBuffer.CopyToByteArray(hash, out hashArray);
var hmac = hashArray.Select(b => Convert.ToInt32(b)).ToArray();
var offset = hmac[19] & 0xF;
var code =
(hmac[offset + 0] & 0x7F) << 24
| (hmac[offset + 1] & 0xFF) << 16
| (hmac[offset + 2] & 0xFF) << 8
| (hmac[offset + 3] & 0xFF);
return code % (int)Math.Pow(10, digits);
}
开发者ID:mbmccormick,项目名称:Authenticator,代码行数:28,代码来源:Otp.cs
示例6: VerifyIncrementalResult
private static void VerifyIncrementalResult(HashAlgorithm referenceAlgorithm, IncrementalHash incrementalHash)
{
byte[] referenceHash = referenceAlgorithm.ComputeHash(s_inputBytes);
const int StepA = 13;
const int StepB = 7;
int position = 0;
while (position < s_inputBytes.Length - StepA)
{
incrementalHash.AppendData(s_inputBytes, position, StepA);
position += StepA;
}
incrementalHash.AppendData(s_inputBytes, position, s_inputBytes.Length - position);
byte[] incrementalA = incrementalHash.GetHashAndReset();
Assert.Equal(referenceHash, incrementalA);
// Now try again, verifying both immune to step size behaviors, and that GetHashAndReset resets.
position = 0;
while (position < s_inputBytes.Length - StepB)
{
incrementalHash.AppendData(s_inputBytes, position, StepA);
position += StepA;
}
incrementalHash.AppendData(s_inputBytes, position, s_inputBytes.Length - position);
byte[] incrementalB = incrementalHash.GetHashAndReset();
Assert.Equal(referenceHash, incrementalB);
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:33,代码来源:IncrementalHashTests.cs
示例7: GetCode
/// <summary>Compute the one-time code for the given parameters.</summary>
/// <param name="algorithm">The hashing algorithm for the HMAC computation.</param>
/// <param name="secret">The ASCII-encoded base32-encoded shared secret.</param>
/// <param name="datetime">The date with time for which the one-time code must be computed.</param>
/// <param name="digits">The number of digits of the one-time codes.</param>
/// <param name="period">The period step used for the HMAC counter computation.</param>
/// <returns>The one-time code for the given date.</returns>
public static int GetCode(
HashAlgorithm algorithm,
string secret,
DateTime datetime,
int digits = Otp.DefaultDigits,
int period = Totp.DefaultPeriod)
{
Contract.Requires<ArgumentOutOfRangeException>(Enum.IsDefined(typeof(HashAlgorithm), algorithm));
Contract.Requires<ArgumentOutOfRangeException>(algorithm != HashAlgorithm.Unknown);
Contract.Requires<ArgumentNullException>(secret != null);
Contract.Requires<ArgumentNullException>(datetime != null);
Contract.Requires<ArgumentException>(Enum.IsDefined(typeof(DateTimeKind), datetime.Kind));
Contract.Requires<ArgumentException>(datetime.Kind != DateTimeKind.Unspecified);
Contract.Requires<ArgumentOutOfRangeException>(digits > 0);
Contract.Requires<ArgumentOutOfRangeException>(period > 0);
Contract.Ensures(Contract.Result<int>() > 0);
Contract.Ensures(Contract.Result<int>() < Math.Pow(10, digits));
datetime = datetime.Kind == DateTimeKind.Utc ? datetime : datetime.ToUniversalTime();
var unixTime = datetime.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
var counter = (long) (unixTime * 1000) / (period * 1000);
return Otp.GetCode(algorithm, secret, counter, digits);
}
开发者ID:kappa7194,项目名称:otp,代码行数:32,代码来源:Totp.cs
示例8: WriteHash
public static void WriteHash(XmlNode node, HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc) {
if (node is ICanonicalizableNode) {
((ICanonicalizableNode) node).WriteHash(hash, docPos, anc);
} else {
WriteHashGenericNode(node, hash, docPos, anc);
}
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:C14NUtil.cs
示例9: VerifySignatureWithHashAlgorithm
private static void VerifySignatureWithHashAlgorithm(AsymmetricSignatureFormatter formatter, AsymmetricSignatureDeformatter deformatter, HashAlgorithm hashAlgorithm)
{
byte[] signature = formatter.CreateSignature(hashAlgorithm);
Assert.True(deformatter.VerifySignature(hashAlgorithm, signature));
signature[signature.Length - 1] ^= 0xff;
Assert.False(deformatter.VerifySignature(hashAlgorithm, signature));
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:8,代码来源:AsymmetricSignatureFormatter.cs
示例10: ValidateHashAlgorithm
public static bool ValidateHashAlgorithm(HashAlgorithm value)
{
if ((((value != HashAlgorithm.None) && (value != HashAlgorithm.Md2)) && ((value != HashAlgorithm.Md4) && (value != HashAlgorithm.Md5))) && (value != HashAlgorithm.Sha))
{
return (value == HashAlgorithm.Mac);
}
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ValidationUtility.cs
示例11: Compute
public static void Compute(HashAlgorithm hashAlgorithm, IUVStream<ArraySegment<byte>> stream, Action<byte[]> callback)
{
var hs = new HashStream(hashAlgorithm, stream);
hs.Complete += () => {
callback(hs.Hash);
hs.Dispose();
};
}
开发者ID:lrdcasimir,项目名称:LibuvSharp,代码行数:8,代码来源:HashStream.cs
示例12: GetDigestedBytes
internal byte[] GetDigestedBytes(HashAlgorithm hash) {
m_c14nDoc.WriteHash(hash, DocPosition.BeforeRootElement, m_ancMgr);
hash.TransformFinalBlock(new byte[0], 0, 0);
byte[] res = (byte[]) hash.Hash.Clone();
// reinitialize the hash so it is still usable after the call
hash.Initialize();
return res;
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:8,代码来源:ExcCanonicalXml.cs
示例13: 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
示例14: ComputeString
public static void ComputeString(HashAlgorithm hashAlgorithm, IUVStream stream, Action<string> callback)
{
var hs = new HashStream(hashAlgorithm, stream);
hs.Complete += () => {
callback(hs.HashString);
hs.Dispose();
};
}
开发者ID:oskarwkarlsson,项目名称:LibuvSharp,代码行数:8,代码来源:HashStream.cs
示例15: PrintHash
// prints the hash of a specified input to the console
public static void PrintHash(string name, HashAlgorithm algo, byte[] data)
{
// compute the hash of the input data..
byte[] hash = algo.ComputeHash(data);
// ..and write the hash to the console
Console.WriteLine(name + BytesToHex(hash));
// dispose of the hash algorithm; we do not need to hash more data with it
algo.Clear();
}
开发者ID:maikgreubel,项目名称:securitylibrary,代码行数:10,代码来源:Hashing.cs
示例16: WriteHashGenericNode
public static void WriteHashGenericNode(XmlNode node, HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc) {
if (node == null)
throw new ArgumentNullException("node");
XmlNodeList childNodes = node.ChildNodes;
foreach (XmlNode childNode in childNodes) {
WriteHash(childNode, hash, docPos, anc);
}
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:9,代码来源:C14NUtil.cs
示例17: CacheManagerStreamWriter
public CacheManagerStreamWriter(out KeyCollection keys, int blockLength, HashAlgorithm hashAlgorithm, CacheManager cacheManager, BufferManager bufferManager)
{
keys = _keyList;
_hashAlgorithm = hashAlgorithm;
_cacheManager = cacheManager;
_bufferManager = bufferManager;
_blockBuffer = bufferManager.TakeBuffer(blockLength);
_blockBufferLength = blockLength;
}
开发者ID:networkelements,项目名称:Library,代码行数:9,代码来源:CacheManagerStreamWriter.cs
示例18: Perf
static void Perf(HashAlgorithm digest)
{
Console.WriteLine ("Performance tests for different block sizes, 30 seconds each");
int block = 1;
while (block <= 64 * 1024) {
Speed (digest, block);
block <<= 2;
}
}
开发者ID:symform,项目名称:crimson,代码行数:9,代码来源:hashperf.cs
示例19: VerifySignature
protected static void VerifySignature(AsymmetricSignatureFormatter formatter, AsymmetricSignatureDeformatter deformatter, HashAlgorithm hashAlgorithm, string hashAlgorithmName)
{
formatter.SetHashAlgorithm(hashAlgorithmName);
deformatter.SetHashAlgorithm(hashAlgorithmName);
byte[] hash = hashAlgorithm.ComputeHash(HelloBytes);
VerifySignatureWithHashBytes(formatter, deformatter, hash);
VerifySignatureWithHashAlgorithm(formatter, deformatter, hashAlgorithm);
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:10,代码来源:AsymmetricSignatureFormatter.cs
示例20: Hash
public static byte[] Hash(HashAlgorithm alg, byte[] message)
{
switch (alg)
{
case HashAlgorithm.SHA256:
return SHA256.Hash(message);
default:
throw new Exception("Invalid HashAlgorithm");
}
}
开发者ID:prizm-labs,项目名称:PokerMultiScreenDemo_HH,代码行数:10,代码来源:Crypto.cs
注:本文中的HashAlgorithm类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论