mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Read-mode working
Write-mode does not create exceptions but still doesn't work
This commit is contained in:
50
ModernKeePassLib/Cryptography/CryptographicHashExtensions.cs
Normal file
50
ModernKeePassLib/Cryptography/CryptographicHashExtensions.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
|
||||
namespace ModernKeePassLibPCL.Cryptography
|
||||
{
|
||||
public static class CryptographicHashExtensions
|
||||
{
|
||||
public static int TransformBlock(this CryptographicHash hash, byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
|
||||
{
|
||||
byte[] buffer;
|
||||
if (inputCount < inputBuffer.Length)
|
||||
{
|
||||
buffer = new byte[inputCount];
|
||||
Array.Copy(inputBuffer, inputOffset, buffer, 0, inputCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = inputBuffer;
|
||||
}
|
||||
|
||||
hash.Append(buffer.AsBuffer());
|
||||
if (outputBuffer != null)
|
||||
{
|
||||
Array.Copy(inputBuffer, inputOffset, outputBuffer, outputOffset, inputCount);
|
||||
}
|
||||
|
||||
return inputCount;
|
||||
}
|
||||
|
||||
public static byte[] TransformFinalBlock(this CryptographicHash hash, byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
hash.TransformBlock(inputBuffer, inputOffset, inputCount, null, 0);
|
||||
if (inputCount == inputBuffer.Length)
|
||||
{
|
||||
return inputBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
var buffer = new byte[inputCount];
|
||||
Array.Copy(inputBuffer, inputOffset, buffer, 0, inputCount);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user