本文整理汇总了C#中IDigest.ComputeHash方法的典型用法代码示例。如果您正苦于以下问题:C# IDigest.ComputeHash方法的具体用法?C# IDigest.ComputeHash怎么用?C# IDigest.ComputeHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDigest
的用法示例。
在下文中一共展示了IDigest.ComputeHash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexGenerator
/// <summary>
/// Constructs a new index generator
/// </summary>
///
/// <param name="Seed">A seed of arbitrary length to initialize the index generator</param>
/// <param name="EncParam">NtruEncrypt parameters</param>
public IndexGenerator(byte[] Seed, NTRUParameters EncParam)
{
_N = EncParam.N;
_C = EncParam.CBits;
int minCallsR = EncParam.MinIGFHashCalls;
_digestEngine = GetDigest(EncParam.Digest);
_hashLen = _digestEngine.DigestSize;
_Z = Seed;
_callCounter = 0;
_bitBuffer = new BitString();
while (_callCounter < minCallsR)
{
byte[] data = new byte[_Z.Length + 4];
Buffer.BlockCopy(_Z, 0, data, 0, _Z.Length);
Buffer.BlockCopy(IntUtils.IntToBytes(_callCounter), 0, data, _Z.Length, 4);
byte[] H = _digestEngine.ComputeHash(data);
_bitBuffer.AppendBits(H);
_callCounter++;
}
_remLen = minCallsR * 8 * _hashLen;
}
示例2: StandardAuthentication
private bool StandardAuthentication(IDigest hash, Stream stream, byte[] additionalChallenge)
{
// Authenticate (If mode = 1)
// C <= S
// byte PasswordHashMethod
// byte SaltLength
// byte[] Salt
// int Iterations
// byte SrpHashMethod
// int Bit Strength
// byte[] Public B (Size equal to SRP Length)
// C => S
// byte[] Public A (Size equal to SRP Length)
// byte[] Client Proof: H(Public A | Public B | SessionKey)
// C <= S
// Bool Success (if false, done)
// byte[] Server Proof: H(Public B | Public A | SessionKey)
int srpNumberLength = ((int)m_user.SrpStrength) >> 3;
stream.WriteByte((byte)PasswordHashMethod);
stream.WriteByte((byte)m_user.Salt.Length);
stream.Write(m_user.Salt);
stream.Write(m_user.Iterations);
stream.WriteByte((byte)SrpHashMethod);
stream.Write((int)m_user.SrpStrength);
stream.Flush(); //since computing B takes a long time. Go ahead and flush
var param = SrpConstants.Lookup(m_user.SrpStrength);
Srp6Server server = new Srp6Server(param, m_user.VerificationInteger);
BigInteger pubB = server.GenerateServerCredentials();
byte[] pubBBytes = pubB.ToPaddedArray(srpNumberLength);
stream.Write(pubBBytes);
stream.Flush();
//Read from client: A
byte[] pubABytes = stream.ReadBytes(srpNumberLength);
BigInteger pubA = new BigInteger(1, pubABytes);
//Calculate Session Key
BigInteger S = server.CalculateSecret(hash, pubA);
byte[] SBytes = S.ToPaddedArray(srpNumberLength);
byte[] clientProofCheck = hash.ComputeHash(pubABytes, pubBBytes, SBytes, additionalChallenge);
byte[] serverProof = hash.ComputeHash(pubBBytes, pubABytes, SBytes, additionalChallenge);
byte[] clientProof = stream.ReadBytes(hash.GetDigestSize());
if (clientProof.SecureEquals(clientProofCheck))
{
stream.Write(true);
stream.Write(serverProof);
stream.Flush();
byte[] K = hash.ComputeHash(pubABytes, SBytes, pubBBytes).Combine(hash.ComputeHash(pubBBytes, SBytes, pubABytes));
byte[] ticket = CreateSessionData(K, m_user);
SessionSecret = K;
stream.Write((short)ticket.Length);
stream.Write(ticket);
stream.Flush();
return true;
}
stream.Write(false);
stream.Flush();
return false;
}
示例3: ResumeTicket
private bool ResumeTicket(IDigest hash, Stream stream, byte[] additionalChallenge)
{
// Successful Resume Session (If mode = 1)
// C => S
// byte ChallengeLength
// byte[] A = Challenge
// int16 TicketLength
// byte[] Ticket
// C <= S
// bool IsSuccess = true
// byte HashMethod
// byte ChallengeLength
// byte[] B = Challenge
// C => S
// byte[] M1 = H(A | B | SessionKey)
// Bool Success (if false, done)
// C <= S
// byte[] M2 = H(B | A | SessionKey)
// Failed Resume Session
// C => S
// byte ChallengeLength
// byte[] A = Challenge
// int16 TicketLength
// byte[] Ticket
// C <= S
// bool IsSuccess = false
// Goto Authenticate Code
byte[] a = stream.ReadBytes(stream.ReadNextByte());
int ticketLength = stream.ReadInt16();
if (ticketLength < 0 || ticketLength > 10000)
return false;
byte[] ticket = stream.ReadBytes(ticketLength);
if (TryLoadTicket(ticket, m_user, out SessionSecret))
{
stream.Write(true);
stream.WriteByte((byte)SrpHashMethod);
byte[] b = SaltGenerator.Create(16);
stream.WriteByte(16);
stream.Write(b);
stream.Flush();
byte[] clientProofCheck = hash.ComputeHash(a, b, SessionSecret, additionalChallenge);
byte[] serverProof = hash.ComputeHash(b, a, SessionSecret, additionalChallenge);
byte[] clientProof = stream.ReadBytes(hash.GetDigestSize());
if (clientProof.SecureEquals(clientProofCheck))
{
stream.Write(true);
stream.Write(serverProof);
stream.Flush();
return true;
}
stream.Write(false);
return false;
}
stream.Write(false);
return StandardAuthentication(hash, stream, additionalChallenge);
}