WIP KeePassLibPCL

This commit is contained in:
bg45
2017-09-23 09:42:48 -04:00
parent 668afbe817
commit 9d78d59a15
108 changed files with 3283 additions and 181 deletions

View File

@@ -0,0 +1,4 @@
MainPackage=C:\Users\bg45\source\repos\ModernKeePass\ModernKeePass\bin\Release\ModernKeePass_1.1.0.6_AnyCPU.appx
SymbolPackage=C:\Users\bg45\source\repos\ModernKeePass\ModernKeePass\AppPackages\ModernKeePass_1.1.0.6_Test\ModernKeePass_1.1.0.6_AnyCPU.appxsym
ResourcePack=C:\Users\bg45\source\repos\ModernKeePass\ModernKeePass\bin\Release\ModernKeePass_1.1.0.6_scale-140.appx
ResourcePack=C:\Users\bg45\source\repos\ModernKeePass\ModernKeePass\bin\Release\ModernKeePass_1.1.0.6_scale-180.appx

View File

@@ -159,8 +159,8 @@
</Page>
</ItemGroup>
<ItemGroup>
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.32947, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.32947\lib\portable46-net451+win81+wpa81\ModernKeePassLibPCL.dll</HintPath>
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.33588, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.33588\lib\portable46-net451+win81+wpa81\ModernKeePassLibPCL.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
<Identity Name="wismna.ModernKeePass" Publisher="CN=0719A91A-C322-4EE0-A257-E60733EECF06" Version="1.1.0.2" />
<Identity Name="wismna.ModernKeePass" Publisher="CN=0719A91A-C322-4EE0-A257-E60733EECF06" Version="1.1.0.6" />
<Properties>
<DisplayName>ModernKeePass</DisplayName>
<PublisherDisplayName>wismna</PublisherDisplayName>

View File

@@ -4,7 +4,7 @@
<package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="win81" />
<package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="win81" />
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" targetFramework="win81" />
<package id="ModernKeePassLibPCL" version="2.28.1.32947" targetFramework="win81" />
<package id="ModernKeePassLibPCL" version="2.28.1.33588" targetFramework="win81" />
<package id="NETStandard.Library" version="2.0.0" targetFramework="win81" />
<package id="PCLCrypto" version="2.0.147" targetFramework="win81" />
<package id="PCLStorage" version="1.0.2" targetFramework="win81" />

View File

@@ -25,7 +25,8 @@ using System.Security;
using System.Diagnostics;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
#else
#if !KeePassRT
@@ -124,7 +125,7 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
Array.Copy(pbKey, pbLocalKey, 32);
#if ModernKeePassLibPCL
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.
/*var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.
OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(pbLocalKey);
if (bEncrypt)
@@ -138,6 +139,27 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
key, pbLocalIV);
return new CryptoStream(s, decryptor, CryptoStreamMode.Read);
}
*/
var provider = SymmetricKeyAlgorithmProvider.
OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(pbLocalKey));
using (var ms = new MemoryStream())
{
s.CopyTo(ms);
var data = CryptographicBuffer.CreateFromByteArray(ms.ToArray());
byte[] resultByteArray;
if (bEncrypt)
{
var encrypted = CryptographicEngine.Encrypt(key, data, CryptographicBuffer.CreateFromByteArray(pbLocalIV));
CryptographicBuffer.CopyToByteArray(encrypted, out resultByteArray);
}
else
{
var decrypted = CryptographicEngine.Decrypt(key, data, CryptographicBuffer.CreateFromByteArray(pbLocalIV));
CryptographicBuffer.CopyToByteArray(decrypted, out resultByteArray);
}
return new MemoryStream(resultByteArray, true);
}
#else
#if !KeePassRT

View File

@@ -20,7 +20,7 @@
using System;
using System.Security;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
@@ -29,6 +29,7 @@ using System.Diagnostics;
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLibPCL.Cryptography
{
@@ -42,7 +43,7 @@ namespace ModernKeePassLibPCL.Cryptography
private byte[] m_pbEntropyPool = new byte[64];
private uint m_uCounter;
#if ModernKeePassLibPCL
private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
//private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
#else
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
#endif
@@ -107,8 +108,11 @@ namespace ModernKeePassLibPCL.Cryptography
if(pbEntropy.Length >= 64)
{
#if ModernKeePassLibPCL
var shaNew = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
pbNewData = shaNew.HashData(pbEntropy);
/*var shaNew = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
pbNewData = shaNew.HashData(pbEntropy);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbEntropy));
CryptographicBuffer.CopyToByteArray(buffer, out pbNewData);
#else
#if !KeePassLibSD
@@ -129,8 +133,11 @@ namespace ModernKeePassLibPCL.Cryptography
byte[] pbFinal = ms.ToArray();
#if ModernKeePassLibPCL
var shaPool = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
m_pbEntropyPool = shaPool.HashData(pbFinal);
/*var shaPool = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
m_pbEntropyPool = shaPool.HashData(pbFinal);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbFinal));
CryptographicBuffer.CopyToByteArray(buffer, out m_pbEntropyPool);
#else
#if !KeePassLibSD
@@ -250,7 +257,8 @@ namespace ModernKeePassLibPCL.Cryptography
private byte[] GetCspData()
{
byte[] pbCspRandom = new byte[32];
m_rng.GetBytes(pbCspRandom);
//m_rng.GetBytes(pbCspRandom);
CryptographicBuffer.CopyToByteArray(CryptographicBuffer.GenerateRandom(32), out pbCspRandom);
return pbCspRandom;
}
@@ -280,8 +288,13 @@ namespace ModernKeePassLibPCL.Cryptography
}
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbFinal);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbFinal);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbFinal));
byte[] result;
CryptographicBuffer.CopyToByteArray(buffer, out result);
return result;
#else
SHA256Managed sha256 = new SHA256Managed();
return sha256.ComputeHash(pbFinal);

View File

@@ -19,8 +19,9 @@
using System;
using System.Diagnostics;
using Windows.Security.Cryptography.Core;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
@@ -116,8 +117,12 @@ namespace ModernKeePassLibPCL.Cryptography
else if(genAlgorithm == CrsAlgorithm.Salsa20)
{
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbKey32 = sha256.HashData(pbKey);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbKey32 = sha256.HashData(pbKey);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbKey));
byte[] pbKey32;
CryptographicBuffer.CopyToByteArray(buffer, out pbKey32);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbKey32 = sha256.ComputeHash(pbKey);

View File

@@ -22,13 +22,14 @@ using System.Collections.Generic;
using System.Text;
using System.IO;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
using System.Diagnostics;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLibPCL.Cryptography
{
@@ -37,7 +38,8 @@ namespace ModernKeePassLibPCL.Cryptography
private Stream m_sBaseStream;
private bool m_bWriting;
#if ModernKeePassLibPCL
private ICryptoTransform m_hash;
//private ICryptoTransform m_hash;
private CryptographicHash m_hash;
#else
private HashAlgorithm m_hash;
#endif
@@ -76,7 +78,8 @@ namespace ModernKeePassLibPCL.Cryptography
}
#if ModernKeePassLibPCL
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm? hashAlgorithm)
//public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm? hashAlgorithm)
public HashingStreamEx(Stream sBaseStream, bool bWriting, string hashAlgorithm)
#else
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm)
#endif
@@ -87,7 +90,8 @@ namespace ModernKeePassLibPCL.Cryptography
m_sBaseStream = sBaseStream;
m_bWriting = bWriting;
#if ModernKeePassLibPCL
m_hash = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithm.Sha256).CreateHash();
//m_hash = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithm.Sha256).CreateHash();
m_hash = HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithmNames.Sha256).CreateHash();
#elif !KeePassLibSD
m_hash = (hashAlgorithm ?? new SHA256Managed());
#else // KeePassLibSD
@@ -101,14 +105,14 @@ namespace ModernKeePassLibPCL.Cryptography
if (m_hash == null) { Debug.Assert(false); return; }
// Validate hash algorithm
if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
/*if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
(m_hash.InputBlockSize != 1) || (m_hash.OutputBlockSize != 1))
{
#if false && DEBUG
MessageService.ShowWarning("Broken HashAlgorithm object in HashingStreamEx.");
#endif
m_hash = null;
}
}*/
}
public override void Flush()
@@ -128,9 +132,10 @@ namespace ModernKeePassLibPCL.Cryptography
{
try
{
m_hash.TransformFinalBlock(new byte[0], 0, 0);
//m_hash.TransformFinalBlock(new byte[0], 0, 0);
#if ModernKeePassLibPCL
m_pbFinalHash = (m_hash as CryptographicHash).GetValueAndReset ();
//m_pbFinalHash = (m_hash as CryptographicHash).GetValueAndReset ();
CryptographicBuffer.CopyToByteArray(m_hash.GetValueAndReset(), out m_pbFinalHash);
#else
m_pbFinalHash = m_hash.Hash;
#endif
@@ -172,7 +177,8 @@ namespace ModernKeePassLibPCL.Cryptography
#endif
if((m_hash != null) && (nRead > 0))
m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);
//m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);
m_hash.Append(CryptographicBuffer.CreateFromByteArray(pbBuffer));
#if DEBUG
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
@@ -191,7 +197,8 @@ namespace ModernKeePassLibPCL.Cryptography
#endif
if ((m_hash != null) && (nCount > 0))
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);
//m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);
m_hash.Append(CryptographicBuffer.CreateFromByteArray(pbBuffer));
#if DEBUG
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));

View File

@@ -21,13 +21,14 @@ using System;
using System.Collections.Generic;
using System.Text;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
using System.Globalization;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
#if (!KeePassLibSD && !KeePassRT)
namespace ModernKeePassLibPCL.Cryptography
@@ -47,9 +48,13 @@ namespace ModernKeePassLibPCL.Cryptography
Array.Reverse(pbText); // Big-Endian
#if ModernKeePassLibPCL
var hsha1 = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1).CreateHash(pbSecret);
/*var hsha1 = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1).CreateHash(pbSecret);
hsha1.Append(pbText);
var pbHash = hsha1.GetValueAndReset();
var pbHash = hsha1.GetValueAndReset();*/
var hsha1 = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1).CreateHash(CryptographicBuffer.CreateFromByteArray(pbSecret));
hsha1.Append(CryptographicBuffer.CreateFromByteArray(pbText));
byte[] pbHash;
CryptographicBuffer.CopyToByteArray(hsha1.GetValueAndReset(), out pbHash);
#else
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
byte[] pbHash = hsha1.ComputeHash(pbText);

View File

@@ -21,7 +21,7 @@ using System;
using System.Collections.Generic;
using System.Security;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif

View File

@@ -23,7 +23,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
@@ -37,6 +37,8 @@ using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
using Windows.Storage.Streams;
namespace ModernKeePassLibPCL.Keys
{
@@ -178,8 +180,12 @@ namespace ModernKeePassLibPCL.Keys
}
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(ms.ToArray());
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(ms.ToArray());*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(ms.ToArray()));
byte[] pbHash;
CryptographicBuffer.CopyToByteArray(buffer, out pbHash);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbHash = sha256.ComputeHash(ms.ToArray());
@@ -284,8 +290,13 @@ namespace ModernKeePassLibPCL.Keys
return null;
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbNewKey);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
return sha256.HashData(pbNewKey);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
byte[] result;
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbNewKey));
CryptographicBuffer.CopyToByteArray(buffer, out result);
return result;
#else
SHA256Managed sha256 = new SHA256Managed();
return sha256.ComputeHash(pbNewKey);
@@ -307,9 +318,12 @@ namespace ModernKeePassLibPCL.Keys
}
#else
#if ModernKeePassLibPCL
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
/*var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
var key = aes.CreateSymmetricKey(pbKeySeed32);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);*/
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
var key = aes.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(pbKeySeed32));
#else
byte[] pbIV = new byte[16];
Array.Clear(pbIV, 0, pbIV.Length);
@@ -384,9 +398,12 @@ namespace ModernKeePassLibPCL.Keys
aes.Init(true, kp);
#else
#if ModernKeePassLibPCL
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
/*var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
var key = aes.CreateSymmetricKey(pbKey);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);
var iCrypt = WinRTCrypto.CryptographicEngine.CreateEncryptor(key);*/
var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);
var key = aes.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(pbKey));
#else
byte[] pbIV = new byte[16];
Array.Clear(pbIV, 0, pbIV.Length);

View File

@@ -22,13 +22,14 @@ using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLibPCL.Keys
{
@@ -60,8 +61,12 @@ namespace ModernKeePassLibPCL.Keys
if(bPerformHash)
{
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbKeyData);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbKeyData);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbKeyData));
byte[] pbRaw;
CryptographicBuffer.CopyToByteArray(buffer, out pbRaw);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbKeyData);

View File

@@ -26,7 +26,7 @@ using System.Security;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
@@ -37,6 +37,7 @@ using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Serialization;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLibPCL.Keys
{
@@ -139,8 +140,11 @@ namespace ModernKeePassLibPCL.Keys
if(pbKey == null)
{
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
pbKey = sha256.HashData(pbFileData);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
pbKey = sha256.HashData(pbFileData);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbFileData));
CryptographicBuffer.CopyToByteArray(buffer, out pbKey);
#else
SHA256Managed sha256 = new SHA256Managed();
pbKey = sha256.ComputeHash(pbFileData);
@@ -203,8 +207,11 @@ namespace ModernKeePassLibPCL.Keys
ms.Write(pbKey32, 0, 32);
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
pbFinalKey32 = sha256.HashData(ms.ToArray());
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
pbFinalKey32 = sha256.HashData(ms.ToArray());*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(ms.ToArray()));
CryptographicBuffer.CopyToByteArray(buffer, out pbFinalKey32);
#else
SHA256Managed sha256 = new SHA256Managed();
pbFinalKey32 = sha256.ComputeHash(ms.ToArray());

View File

@@ -21,13 +21,14 @@ using System;
using System.Text;
using System.Diagnostics;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
using ModernKeePassLibPCL.Security;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLibPCL.Keys
{
@@ -73,8 +74,12 @@ namespace ModernKeePassLibPCL.Keys
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbPasswordUtf8);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbRaw = sha256.HashData(pbPasswordUtf8);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbPasswordUtf8));
byte[] pbRaw;
CryptographicBuffer.CopyToByteArray(buffer, out pbRaw);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);

View File

@@ -15,12 +15,13 @@
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkProfile>Profile151</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<AssemblyOriginatorKeyFile>KeePassLib.pfx</AssemblyOriginatorKeyFile>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -120,8 +121,8 @@
<None Include="KeePassLib.pfx" />
<None Include="Libs\Windows.winmd" />
<None Include="ModernKeePassLibPCL.nuspec" />
<None Include="project.json" />
<None Include="Utility\MessageService.cs" />
<None Include="packages.config" />
<None Include="Native\NativeLib.cs" />
<None Include="Native\NativeMethods.cs" />
<None Include="Native\NativeMethods.Unix.cs" />
@@ -148,33 +149,6 @@
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
<HintPath>..\packages\PCLCrypto.2.0.147\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\PCLCrypto.dll</HintPath>
</Reference>
<Reference Include="PCLStorage">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.dll</HintPath>
</Reference>
<Reference Include="PCLStorage.Abstractions">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.Abstractions.dll</HintPath>
</Reference>
<Reference Include="PInvoke.BCrypt, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.BCrypt.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.BCrypt.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Kernel32, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Kernel32.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.Kernel32.dll</HintPath>
</Reference>
<Reference Include="PInvoke.NCrypt, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.NCrypt.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.NCrypt.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Windows.Core.0.5.97\lib\portable-net45+win8+wpa81\PInvoke.Windows.Core.dll</HintPath>
</Reference>
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.2.0.0\lib\netstandard1.1\Splat.dll</HintPath>
</Reference>
<Reference Include="Validation, Version=2.4.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
<HintPath>..\packages\Validation.2.4.15\lib\portable-net45+win8+wp8+wpa81\Validation.dll</HintPath>
</Reference>
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libs\Windows.winmd</HintPath>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\Microsoft.Bcl.Build\1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('$(NuGetPackageRoot)\Microsoft.Bcl.Build\1.0.21\build\Microsoft.Bcl.Build.targets')" />
</ImportGroup>
</Project>

View File

@@ -21,7 +21,7 @@ using System;
using System.IO;
#if ModernKeePassLibPCL
using System.Linq;
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
@@ -30,6 +30,7 @@ using System.Text;
using ModernKeePassLibPCL.Native;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
#if KeePassLibSD
using KeePassLibSD;
@@ -251,8 +252,12 @@ namespace ModernKeePassLibPCL.Serialization
if(m_bVerify)
{
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbComputedHash = sha256.HashData(m_pbBuffer);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbComputedHash = sha256.HashData(m_pbBuffer);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(m_pbBuffer));
byte[] pbComputedHash;
CryptographicBuffer.CopyToByteArray(buffer, out pbComputedHash);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] pbComputedHash = sha256.ComputeHash(m_pbBuffer);
@@ -298,8 +303,12 @@ namespace ModernKeePassLibPCL.Serialization
if(m_nBufferPos > 0)
{
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(m_pbBuffer.Where((x, i) => i < m_nBufferPos).ToArray());
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var pbHash = sha256.HashData(m_pbBuffer.Where((x, i) => i < m_nBufferPos).ToArray());*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(m_pbBuffer.Where((x, i) => i < m_nBufferPos).ToArray()));
byte[] pbHash;
CryptographicBuffer.CopyToByteArray(buffer, out pbHash);
#else
SHA256Managed sha256 = new SHA256Managed();

View File

@@ -34,7 +34,7 @@ using System.Security.Cryptography.X509Certificates;
#if ModernKeePassLibPCL
using Windows.Storage;
using PCLStorage;
//using PCLStorage;
#endif
using ModernKeePassLibPCL.Utility;
@@ -432,12 +432,12 @@ namespace ModernKeePassLibPCL.Serialization
private static Stream OpenReadLocal(IOConnectionInfo ioc)
{
#if ModernKeePassLibPCL
if (ioc.StorageFile != null)
{
/*if (ioc.StorageFile != null)
{*/
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
}
/*}
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;*/
#else
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
FileShare.Read);
@@ -478,12 +478,12 @@ namespace ModernKeePassLibPCL.Serialization
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
{
#if ModernKeePassLibPCL
if (ioc.StorageFile != null)
{
/*if (ioc.StorageFile != null)
{*/
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
}
/*}
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
return file.OpenAsync(FileAccess.ReadAndWrite).Result;
return file.OpenAsync(FileAccess.ReadAndWrite).Result;*/
#else
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
FileShare.None);
@@ -502,8 +502,9 @@ namespace ModernKeePassLibPCL.Serialization
RaiseIOAccessPreEvent(ioc, IOAccessType.Exists);
#if ModernKeePassLibPCL
if(ioc.IsLocalFile())
return (FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result != null);
/*if(ioc.IsLocalFile())
return (FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result != null);*/
return ioc.StorageFile.IsAvailable;
#else
if(ioc.IsLocalFile()) return File.Exists(ioc.Path);
#endif
@@ -546,8 +547,8 @@ namespace ModernKeePassLibPCL.Serialization
#if ModernKeePassLibPCL
if (!ioc.IsLocalFile()) return;
ioc.StorageFile?.DeleteAsync().GetResults();
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
file.DeleteAsync().RunSynchronously();
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
file.DeleteAsync().RunSynchronously();*/
#else
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
#endif
@@ -587,8 +588,8 @@ namespace ModernKeePassLibPCL.Serialization
#if ModernKeePassLibPCL
if (!iocFrom.IsLocalFile()) return;
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetResults();
var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
file.MoveAsync(iocTo.Path).RunSynchronously();
/*var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
file.MoveAsync(iocTo.Path).RunSynchronously();*/
#else
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
#endif
@@ -656,7 +657,7 @@ namespace ModernKeePassLibPCL.Serialization
return true;
}
#endif
#if !ModernKeePassLibPCL
internal static void DisposeResponse(WebResponse wr, bool bGetStream)
{
if(wr == null) return;
@@ -674,7 +675,7 @@ namespace ModernKeePassLibPCL.Serialization
try { wr.Dispose(); }
catch(Exception) { Debug.Assert(false); }
}
#endif
public static byte[] ReadFile(IOConnectionInfo ioc)
{
Stream sIn = null;

View File

@@ -25,9 +25,9 @@ using System.Net;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Diagnostics;
using Windows.Storage;
#if ModernKeePassLibPCL
using PCLStorage;
using Windows.Storage;
//using PCLStorage;
#endif
using ModernKeePassLibPCL.Interfaces;

View File

@@ -24,7 +24,7 @@ using System.IO;
using System.Diagnostics;
using System.Security;
#if ModernKeePassLibPCL
using PCLCrypto;
using Windows.Security.Cryptography;
#else
using System.Security.Cryptography;
#endif
@@ -42,6 +42,7 @@ using ModernKeePassLibPCL.Interfaces;
using ModernKeePassLibPCL.Keys;
using ModernKeePassLibPCL.Resources;
using ModernKeePassLibPCL.Utility;
using Windows.Security.Cryptography.Core;
namespace ModernKeePassLibPCL.Serialization
{
@@ -221,8 +222,11 @@ namespace ModernKeePassLibPCL.Serialization
msHeader.Dispose();
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
m_pbHashOfHeader = sha256.HashData(pbHeader);
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
m_pbHashOfHeader = sha256.HashData(pbHeader);*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbHeader));
CryptographicBuffer.CopyToByteArray(buffer, out m_pbHashOfHeader);
#else
SHA256Managed sha256 = new SHA256Managed();
m_pbHashOfHeader = sha256.ComputeHash(pbHeader);
@@ -348,8 +352,12 @@ namespace ModernKeePassLibPCL.Serialization
ms.Write(pKey32, 0, 32);
#if ModernKeePassLibPCL
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var aesKey = sha256.HashData(ms.ToArray());
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
var aesKey = sha256.HashData(ms.ToArray());*/
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(ms.ToArray()));
byte[] aesKey;
CryptographicBuffer.CopyToByteArray(buffer, out aesKey);
#else
SHA256Managed sha256 = new SHA256Managed();
byte[] aesKey = sha256.ComputeHash(ms.ToArray());

Some files were not shown because too many files have changed in this diff Show More