Read-mode working

Write-mode does not create exceptions but still doesn't work
This commit is contained in:
2017-09-25 14:50:47 +02:00
parent 3bf8015280
commit 34996da19d
38 changed files with 341 additions and 358 deletions

View File

@@ -23,7 +23,7 @@ using System.Text;
using System.IO;
using System.Security;
using System.Diagnostics;
using Windows.Storage.Streams;
#if ModernKeePassLibPCL
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
@@ -116,7 +116,7 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
private static Stream CreateStream(Stream s, bool bEncrypt, byte[] pbKey, byte[] pbIV)
{
StandardAesEngine.ValidateArguments(s, bEncrypt, pbKey, pbIV);
ValidateArguments(s, bEncrypt, pbKey, pbIV);
byte[] pbLocalIV = new byte[16];
Array.Copy(pbIV, pbLocalIV, 16);
@@ -201,12 +201,12 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
public Stream EncryptStream(Stream sPlainText, byte[] pbKey, byte[] pbIV)
{
return StandardAesEngine.CreateStream(sPlainText, true, pbKey, pbIV);
return CreateStream(sPlainText, true, pbKey, pbIV);
}
public Stream DecryptStream(Stream sEncrypted, byte[] pbKey, byte[] pbIV)
{
return StandardAesEngine.CreateStream(sEncrypted, false, pbKey, pbIV);
return CreateStream(sEncrypted, false, pbKey, pbIV);
}
}
}

View 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;
}
}
}
}

View File

@@ -53,7 +53,7 @@ namespace ModernKeePassLibPCL.Cryptography
public override bool CanRead
{
get { return !m_bWriting; }
get { return /*!m_bWriting;*/true; }
}
public override bool CanSeek
@@ -160,7 +160,7 @@ namespace ModernKeePassLibPCL.Cryptography
public override int Read(byte[] pbBuffer, int nOffset, int nCount)
{
if(m_bWriting) throw new InvalidOperationException();
//if(m_bWriting) throw new InvalidOperationException();
int nRead = m_sBaseStream.Read(pbBuffer, nOffset, nCount);
int nPartialRead = nRead;