mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Added more tests
Code cleanup in Lib WIP new VM for OpendatabaseControl WIP KDBX4 file save - still not working
This commit is contained in:

committed by
BONNEVILLE Geoffroy

parent
278b2759d5
commit
53a54252e3
61
ModernKeePassLib/Cryptography/Hash/HashAlgorithm.cs
Normal file
61
ModernKeePassLib/Cryptography/Hash/HashAlgorithm.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography.Hash
|
||||
{
|
||||
public abstract class HashAlgorithm: IDisposable
|
||||
{
|
||||
protected IDigest Digest;
|
||||
|
||||
public byte[] Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = new byte[Digest.GetDigestSize()];
|
||||
Digest.DoFinal(result, 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanReuseTransform => true;
|
||||
public bool CanTransformMultipleBlocks => true;
|
||||
|
||||
public byte[] ComputeHash(byte[] value)
|
||||
{
|
||||
return ComputeHash(value, 0, value.Length);
|
||||
}
|
||||
|
||||
public byte[] ComputeHash(byte[] value, int offset, int length)
|
||||
{
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
|
||||
byte[] resBuf = new byte[Digest.GetDigestSize()];
|
||||
Digest.BlockUpdate(value, 0, length);
|
||||
Digest.DoFinal(resBuf, 0);
|
||||
|
||||
return resBuf;
|
||||
}
|
||||
|
||||
|
||||
public void TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
|
||||
{
|
||||
Digest.BlockUpdate(inputBuffer, inputOffset, inputCount);
|
||||
if ((outputBuffer != null) && ((inputBuffer != outputBuffer) || (inputOffset != outputOffset)))
|
||||
Buffer.BlockCopy(inputBuffer, inputOffset, outputBuffer, outputOffset, inputCount);
|
||||
}
|
||||
|
||||
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
Digest.BlockUpdate(inputBuffer, inputOffset, inputCount);
|
||||
byte[] outputBytes = new byte[inputCount];
|
||||
if (inputCount != 0)
|
||||
Buffer.BlockCopy(inputBuffer, inputOffset, outputBytes, 0, inputCount);
|
||||
return outputBytes;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Digest.Reset();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user