mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
WIP KeePassLibPCL
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
ModernKeePass/BundleArtifacts/neutral.txt
Normal file
4
ModernKeePass/BundleArtifacts/neutral.txt
Normal 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
|
@@ -159,8 +159,8 @@
|
|||||||
</Page>
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.32947, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="ModernKeePassLibPCL, Version=2.28.1.33588, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.32947\lib\portable46-net451+win81+wpa81\ModernKeePassLibPCL.dll</HintPath>
|
<HintPath>..\packages\ModernKeePassLibPCL.2.28.1.33588\lib\portable46-net451+win81+wpa81\ModernKeePassLibPCL.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
|
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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">
|
<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>
|
<Properties>
|
||||||
<DisplayName>ModernKeePass</DisplayName>
|
<DisplayName>ModernKeePass</DisplayName>
|
||||||
<PublisherDisplayName>wismna</PublisherDisplayName>
|
<PublisherDisplayName>wismna</PublisherDisplayName>
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="win81" />
|
<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.Platforms" version="2.0.0" targetFramework="win81" />
|
||||||
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" 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="NETStandard.Library" version="2.0.0" targetFramework="win81" />
|
||||||
<package id="PCLCrypto" version="2.0.147" targetFramework="win81" />
|
<package id="PCLCrypto" version="2.0.147" targetFramework="win81" />
|
||||||
<package id="PCLStorage" version="1.0.2" targetFramework="win81" />
|
<package id="PCLStorage" version="1.0.2" targetFramework="win81" />
|
||||||
|
@@ -25,7 +25,8 @@ using System.Security;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if !KeePassRT
|
#if !KeePassRT
|
||||||
@@ -124,7 +125,7 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
|
|||||||
Array.Copy(pbKey, pbLocalKey, 32);
|
Array.Copy(pbKey, pbLocalKey, 32);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.
|
/*var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.
|
||||||
OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
|
OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
|
||||||
var key = provider.CreateSymmetricKey(pbLocalKey);
|
var key = provider.CreateSymmetricKey(pbLocalKey);
|
||||||
if (bEncrypt)
|
if (bEncrypt)
|
||||||
@@ -138,6 +139,27 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
|
|||||||
key, pbLocalIV);
|
key, pbLocalIV);
|
||||||
return new CryptoStream(s, decryptor, CryptoStreamMode.Read);
|
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
|
#else
|
||||||
|
|
||||||
#if !KeePassRT
|
#if !KeePassRT
|
||||||
@@ -175,7 +197,7 @@ namespace ModernKeePassLibPCL.Cryptography.Cipher
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream EncryptStream(Stream sPlainText, byte[] pbKey, byte[] pbIV)
|
public Stream EncryptStream(Stream sPlainText, byte[] pbKey, byte[] pbIV)
|
||||||
{
|
{
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
@@ -29,6 +29,7 @@ using System.Diagnostics;
|
|||||||
|
|
||||||
using ModernKeePassLibPCL.Native;
|
using ModernKeePassLibPCL.Native;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Cryptography
|
namespace ModernKeePassLibPCL.Cryptography
|
||||||
{
|
{
|
||||||
@@ -42,7 +43,7 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
private byte[] m_pbEntropyPool = new byte[64];
|
private byte[] m_pbEntropyPool = new byte[64];
|
||||||
private uint m_uCounter;
|
private uint m_uCounter;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
|
//private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
|
||||||
#else
|
#else
|
||||||
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
|
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
|
||||||
#endif
|
#endif
|
||||||
@@ -107,8 +108,11 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
if(pbEntropy.Length >= 64)
|
if(pbEntropy.Length >= 64)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var shaNew = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
|
/*var shaNew = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
|
||||||
pbNewData = shaNew.HashData(pbEntropy);
|
pbNewData = shaNew.HashData(pbEntropy);*/
|
||||||
|
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
|
||||||
|
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbEntropy));
|
||||||
|
CryptographicBuffer.CopyToByteArray(buffer, out pbNewData);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if !KeePassLibSD
|
#if !KeePassLibSD
|
||||||
@@ -119,7 +123,7 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
pbNewData = shaNew.ComputeHash(pbEntropy);
|
pbNewData = shaNew.ComputeHash(pbEntropy);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
lock(m_oSyncRoot)
|
lock(m_oSyncRoot)
|
||||||
@@ -129,8 +133,11 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
|
|
||||||
byte[] pbFinal = ms.ToArray();
|
byte[] pbFinal = ms.ToArray();
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var shaPool = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
|
/*var shaPool = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha512);
|
||||||
m_pbEntropyPool = shaPool.HashData(pbFinal);
|
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
|
#else
|
||||||
|
|
||||||
#if !KeePassLibSD
|
#if !KeePassLibSD
|
||||||
@@ -142,7 +149,7 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
m_pbEntropyPool = shaPool.ComputeHash(pbFinal);
|
m_pbEntropyPool = shaPool.ComputeHash(pbFinal);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ms.Dispose();
|
ms.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +257,8 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
private byte[] GetCspData()
|
private byte[] GetCspData()
|
||||||
{
|
{
|
||||||
byte[] pbCspRandom = new byte[32];
|
byte[] pbCspRandom = new byte[32];
|
||||||
m_rng.GetBytes(pbCspRandom);
|
//m_rng.GetBytes(pbCspRandom);
|
||||||
|
CryptographicBuffer.CopyToByteArray(CryptographicBuffer.GenerateRandom(32), out pbCspRandom);
|
||||||
return pbCspRandom;
|
return pbCspRandom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,13 +288,18 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
return sha256.HashData(pbFinal);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
return sha256.ComputeHash(pbFinal);
|
return sha256.ComputeHash(pbFinal);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a number of cryptographically strong random bytes.
|
/// Get a number of cryptographically strong random bytes.
|
||||||
|
@@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
@@ -116,13 +117,17 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
else if(genAlgorithm == CrsAlgorithm.Salsa20)
|
else if(genAlgorithm == CrsAlgorithm.Salsa20)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var pbKey32 = sha256.HashData(pbKey);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
byte[] pbKey32 = sha256.ComputeHash(pbKey);
|
byte[] pbKey32 = sha256.ComputeHash(pbKey);
|
||||||
#endif
|
#endif
|
||||||
byte[] pbIV = new byte[8] { 0xE8, 0x30, 0x09, 0x4B,
|
byte[] pbIV = new byte[8] { 0xE8, 0x30, 0x09, 0x4B,
|
||||||
0x97, 0x20, 0x5D, 0x2A }; // Unique constant
|
0x97, 0x20, 0x5D, 0x2A }; // Unique constant
|
||||||
|
|
||||||
m_salsa20 = new Salsa20Cipher(pbKey32, pbIV);
|
m_salsa20 = new Salsa20Cipher(pbKey32, pbIV);
|
||||||
|
@@ -22,13 +22,14 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Cryptography
|
namespace ModernKeePassLibPCL.Cryptography
|
||||||
{
|
{
|
||||||
@@ -37,7 +38,8 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
private Stream m_sBaseStream;
|
private Stream m_sBaseStream;
|
||||||
private bool m_bWriting;
|
private bool m_bWriting;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
private ICryptoTransform m_hash;
|
//private ICryptoTransform m_hash;
|
||||||
|
private CryptographicHash m_hash;
|
||||||
#else
|
#else
|
||||||
private HashAlgorithm m_hash;
|
private HashAlgorithm m_hash;
|
||||||
#endif
|
#endif
|
||||||
@@ -76,18 +78,20 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#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
|
#else
|
||||||
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm)
|
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if(sBaseStream == null)
|
if(sBaseStream == null)
|
||||||
throw new ArgumentNullException("sBaseStream");
|
throw new ArgumentNullException("sBaseStream");
|
||||||
|
|
||||||
m_sBaseStream = sBaseStream;
|
m_sBaseStream = sBaseStream;
|
||||||
m_bWriting = bWriting;
|
m_bWriting = bWriting;
|
||||||
#if ModernKeePassLibPCL
|
#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
|
#elif !KeePassLibSD
|
||||||
m_hash = (hashAlgorithm ?? new SHA256Managed());
|
m_hash = (hashAlgorithm ?? new SHA256Managed());
|
||||||
#else // KeePassLibSD
|
#else // KeePassLibSD
|
||||||
@@ -98,17 +102,17 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
try { if(m_hash == null) m_hash = HashAlgorithm.Create(); }
|
try { if(m_hash == null) m_hash = HashAlgorithm.Create(); }
|
||||||
catch(Exception) { }
|
catch(Exception) { }
|
||||||
#endif
|
#endif
|
||||||
if(m_hash == null) { Debug.Assert(false); return; }
|
if (m_hash == null) { Debug.Assert(false); return; }
|
||||||
|
|
||||||
// Validate hash algorithm
|
// 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))
|
(m_hash.InputBlockSize != 1) || (m_hash.OutputBlockSize != 1))
|
||||||
{
|
{
|
||||||
#if false && DEBUG
|
#if false && DEBUG
|
||||||
MessageService.ShowWarning("Broken HashAlgorithm object in HashingStreamEx.");
|
MessageService.ShowWarning("Broken HashAlgorithm object in HashingStreamEx.");
|
||||||
#endif
|
#endif
|
||||||
m_hash = null;
|
m_hash = null;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Flush()
|
public override void Flush()
|
||||||
@@ -128,13 +132,14 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_hash.TransformFinalBlock(new byte[0], 0, 0);
|
//m_hash.TransformFinalBlock(new byte[0], 0, 0);
|
||||||
#if ModernKeePassLibPCL
|
#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
|
#else
|
||||||
m_pbFinalHash = m_hash.Hash;
|
m_pbFinalHash = m_hash.Hash;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch(Exception) { Debug.Assert(false); }
|
catch(Exception) { Debug.Assert(false); }
|
||||||
|
|
||||||
m_hash = null;
|
m_hash = null;
|
||||||
@@ -172,10 +177,11 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((m_hash != null) && (nRead > 0))
|
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
|
#if DEBUG
|
||||||
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return nRead;
|
return nRead;
|
||||||
@@ -190,8 +196,9 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
|
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((m_hash != null) && (nCount > 0))
|
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
|
#if DEBUG
|
||||||
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
||||||
|
@@ -21,13 +21,14 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
#if (!KeePassLibSD && !KeePassRT)
|
#if (!KeePassLibSD && !KeePassRT)
|
||||||
namespace ModernKeePassLibPCL.Cryptography
|
namespace ModernKeePassLibPCL.Cryptography
|
||||||
@@ -47,15 +48,19 @@ namespace ModernKeePassLibPCL.Cryptography
|
|||||||
Array.Reverse(pbText); // Big-Endian
|
Array.Reverse(pbText); // Big-Endian
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var hsha1 = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1).CreateHash(pbSecret);
|
/*var hsha1 = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1).CreateHash(pbSecret);
|
||||||
hsha1.Append(pbText);
|
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
|
#else
|
||||||
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
|
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
|
||||||
byte[] pbHash = hsha1.ComputeHash(pbText);
|
byte[] pbHash = hsha1.ComputeHash(pbText);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint uOffset = (uint)(pbHash[pbHash.Length - 1] & 0xF);
|
uint uOffset = (uint)(pbHash[pbHash.Length - 1] & 0xF);
|
||||||
if((iTruncationOffset >= 0) && (iTruncationOffset < (pbHash.Length - 4)))
|
if((iTruncationOffset >= 0) && (iTruncationOffset < (pbHash.Length - 4)))
|
||||||
uOffset = (uint)iTruncationOffset;
|
uOffset = (uint)iTruncationOffset;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -23,7 +23,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
@@ -37,6 +37,8 @@ using ModernKeePassLibPCL.Native;
|
|||||||
using ModernKeePassLibPCL.Resources;
|
using ModernKeePassLibPCL.Resources;
|
||||||
using ModernKeePassLibPCL.Security;
|
using ModernKeePassLibPCL.Security;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
using Windows.Storage.Streams;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Keys
|
namespace ModernKeePassLibPCL.Keys
|
||||||
{
|
{
|
||||||
@@ -178,13 +180,17 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var pbHash = sha256.HashData(ms.ToArray());
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
byte[] pbHash = sha256.ComputeHash(ms.ToArray());
|
byte[] pbHash = sha256.ComputeHash(ms.ToArray());
|
||||||
#endif
|
#endif
|
||||||
ms.Dispose();
|
ms.Dispose();
|
||||||
return pbHash;
|
return pbHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,13 +290,18 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
return sha256.HashData(pbNewKey);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
return sha256.ComputeHash(pbNewKey);
|
return sha256.ComputeHash(pbNewKey);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TransformKeyManaged(byte[] pbNewKey32, byte[] pbKeySeed32,
|
public static bool TransformKeyManaged(byte[] pbNewKey32, byte[] pbKeySeed32,
|
||||||
ulong uNumRounds)
|
ulong uNumRounds)
|
||||||
@@ -307,9 +318,12 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
|
/*var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
|
||||||
var key = aes.CreateSymmetricKey(pbKeySeed32);
|
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
|
#else
|
||||||
byte[] pbIV = new byte[16];
|
byte[] pbIV = new byte[16];
|
||||||
Array.Clear(pbIV, 0, pbIV.Length);
|
Array.Clear(pbIV, 0, pbIV.Length);
|
||||||
@@ -328,8 +342,8 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
ICryptoTransform iCrypt = r.CreateEncryptor();
|
ICryptoTransform iCrypt = r.CreateEncryptor();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// !iCrypt.CanReuseTransform -- doesn't work with Mono
|
// !iCrypt.CanReuseTransform -- doesn't work with Mono
|
||||||
if((iCrypt == null) || (iCrypt.InputBlockSize != 16) ||
|
if ((iCrypt == null) || (iCrypt.InputBlockSize != 16) ||
|
||||||
(iCrypt.OutputBlockSize != 16))
|
(iCrypt.OutputBlockSize != 16))
|
||||||
{
|
{
|
||||||
Debug.Assert(false, "Invalid ICryptoTransform.");
|
Debug.Assert(false, "Invalid ICryptoTransform.");
|
||||||
@@ -384,9 +398,12 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
aes.Init(true, kp);
|
aes.Init(true, kp);
|
||||||
#else
|
#else
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
|
/*var aes = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesEcb);
|
||||||
var key = aes.CreateSymmetricKey(pbKey);
|
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
|
#else
|
||||||
byte[] pbIV = new byte[16];
|
byte[] pbIV = new byte[16];
|
||||||
Array.Clear(pbIV, 0, pbIV.Length);
|
Array.Clear(pbIV, 0, pbIV.Length);
|
||||||
|
@@ -22,13 +22,14 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLibPCL.Security;
|
using ModernKeePassLibPCL.Security;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Keys
|
namespace ModernKeePassLibPCL.Keys
|
||||||
{
|
{
|
||||||
@@ -60,13 +61,17 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
if(bPerformHash)
|
if(bPerformHash)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var pbRaw = sha256.HashData(pbKeyData);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
byte[] pbRaw = sha256.ComputeHash(pbKeyData);
|
byte[] pbRaw = sha256.ComputeHash(pbKeyData);
|
||||||
#endif
|
#endif
|
||||||
m_pbKey = new ProtectedBinary(true, pbRaw);
|
m_pbKey = new ProtectedBinary(true, pbRaw);
|
||||||
}
|
}
|
||||||
else m_pbKey = new ProtectedBinary(true, pbKeyData);
|
else m_pbKey = new ProtectedBinary(true, pbKeyData);
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@ using System.Security;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
@@ -37,6 +37,7 @@ using ModernKeePassLibPCL.Resources;
|
|||||||
using ModernKeePassLibPCL.Security;
|
using ModernKeePassLibPCL.Security;
|
||||||
using ModernKeePassLibPCL.Serialization;
|
using ModernKeePassLibPCL.Serialization;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Keys
|
namespace ModernKeePassLibPCL.Keys
|
||||||
{
|
{
|
||||||
@@ -139,13 +140,16 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
if(pbKey == null)
|
if(pbKey == null)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
pbKey = sha256.HashData(pbFileData);
|
pbKey = sha256.HashData(pbFileData);*/
|
||||||
|
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
|
||||||
|
var buffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(pbFileData));
|
||||||
|
CryptographicBuffer.CopyToByteArray(buffer, out pbKey);
|
||||||
#else
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
pbKey = sha256.ComputeHash(pbFileData);
|
pbKey = sha256.ComputeHash(pbFileData);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return pbKey;
|
return pbKey;
|
||||||
}
|
}
|
||||||
@@ -203,13 +207,16 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
ms.Write(pbKey32, 0, 32);
|
ms.Write(pbKey32, 0, 32);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
pbFinalKey32 = sha256.HashData(ms.ToArray());
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
pbFinalKey32 = sha256.ComputeHash(ms.ToArray());
|
pbFinalKey32 = sha256.ComputeHash(ms.ToArray());
|
||||||
#endif
|
#endif
|
||||||
ms.Dispose();
|
ms.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateXmlKeyFile(strFilePath, pbFinalKey32);
|
CreateXmlKeyFile(strFilePath, pbFinalKey32);
|
||||||
|
@@ -21,13 +21,14 @@ using System;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLibPCL.Security;
|
using ModernKeePassLibPCL.Security;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Keys
|
namespace ModernKeePassLibPCL.Keys
|
||||||
{
|
{
|
||||||
@@ -73,14 +74,18 @@ namespace ModernKeePassLibPCL.Keys
|
|||||||
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
|
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var pbRaw = sha256.HashData(pbPasswordUtf8);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);
|
byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_psPassword = new ProtectedString(true, pbPasswordUtf8);
|
m_psPassword = new ProtectedString(true, pbPasswordUtf8);
|
||||||
m_pbKeyData = new ProtectedBinary(true, pbRaw);
|
m_pbKeyData = new ProtectedBinary(true, pbRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,12 +15,13 @@
|
|||||||
<OldToolsVersion>2.0</OldToolsVersion>
|
<OldToolsVersion>2.0</OldToolsVersion>
|
||||||
<UpgradeBackupLocation>
|
<UpgradeBackupLocation>
|
||||||
</UpgradeBackupLocation>
|
</UpgradeBackupLocation>
|
||||||
<TargetFrameworkProfile>Profile151</TargetFrameworkProfile>
|
<TargetFrameworkProfile>
|
||||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
</TargetFrameworkProfile>
|
||||||
|
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
|
||||||
<AssemblyOriginatorKeyFile>KeePassLib.pfx</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>KeePassLib.pfx</AssemblyOriginatorKeyFile>
|
||||||
<NuGetPackageImportStamp>
|
<NuGetPackageImportStamp>
|
||||||
</NuGetPackageImportStamp>
|
</NuGetPackageImportStamp>
|
||||||
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
|
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -120,8 +121,8 @@
|
|||||||
<None Include="KeePassLib.pfx" />
|
<None Include="KeePassLib.pfx" />
|
||||||
<None Include="Libs\Windows.winmd" />
|
<None Include="Libs\Windows.winmd" />
|
||||||
<None Include="ModernKeePassLibPCL.nuspec" />
|
<None Include="ModernKeePassLibPCL.nuspec" />
|
||||||
|
<None Include="project.json" />
|
||||||
<None Include="Utility\MessageService.cs" />
|
<None Include="Utility\MessageService.cs" />
|
||||||
<None Include="packages.config" />
|
|
||||||
<None Include="Native\NativeLib.cs" />
|
<None Include="Native\NativeLib.cs" />
|
||||||
<None Include="Native\NativeMethods.cs" />
|
<None Include="Native\NativeMethods.cs" />
|
||||||
<None Include="Native\NativeMethods.Unix.cs" />
|
<None Include="Native\NativeMethods.Unix.cs" />
|
||||||
@@ -148,33 +149,6 @@
|
|||||||
</MonoDevelop>
|
</MonoDevelop>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<ItemGroup>
|
<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">
|
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>Libs\Windows.winmd</HintPath>
|
<HintPath>Libs\Windows.winmd</HintPath>
|
||||||
|
9
ModernKeePassLib/ModernKeePassLibPCL.nuget.targets
Normal file
9
ModernKeePassLib/ModernKeePassLibPCL.nuget.targets
Normal 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>
|
@@ -21,7 +21,7 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
@@ -30,6 +30,7 @@ using System.Text;
|
|||||||
|
|
||||||
using ModernKeePassLibPCL.Native;
|
using ModernKeePassLibPCL.Native;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
#if KeePassLibSD
|
#if KeePassLibSD
|
||||||
using KeePassLibSD;
|
using KeePassLibSD;
|
||||||
@@ -251,13 +252,17 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
if(m_bVerify)
|
if(m_bVerify)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var pbComputedHash = sha256.HashData(m_pbBuffer);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
byte[] pbComputedHash = sha256.ComputeHash(m_pbBuffer);
|
byte[] pbComputedHash = sha256.ComputeHash(m_pbBuffer);
|
||||||
#endif
|
#endif
|
||||||
if((pbComputedHash == null) || (pbComputedHash.Length != 32))
|
if ((pbComputedHash == null) || (pbComputedHash.Length != 32))
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
|
|
||||||
for(int iHashPos = 0; iHashPos < 32; ++iHashPos)
|
for(int iHashPos = 0; iHashPos < 32; ++iHashPos)
|
||||||
@@ -298,8 +303,12 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
if(m_nBufferPos > 0)
|
if(m_nBufferPos > 0)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var pbHash = sha256.HashData(m_pbBuffer.Where((x, i) => i < m_nBufferPos).ToArray());
|
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
|
#else
|
||||||
|
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
@@ -320,7 +329,7 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_bwOutput.Write(pbHash);
|
m_bwOutput.Write(pbHash);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -34,7 +34,7 @@ using System.Security.Cryptography.X509Certificates;
|
|||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using PCLStorage;
|
//using PCLStorage;
|
||||||
#endif
|
#endif
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
|
||||||
@@ -432,12 +432,12 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
private static Stream OpenReadLocal(IOConnectionInfo ioc)
|
private static Stream OpenReadLocal(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if (ioc.StorageFile != null)
|
/*if (ioc.StorageFile != null)
|
||||||
{
|
{*/
|
||||||
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
|
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
|
||||||
}
|
/*}
|
||||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||||
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;
|
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;*/
|
||||||
#else
|
#else
|
||||||
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
|
return new FileStream(ioc.Path, FileMode.Open, FileAccess.Read,
|
||||||
FileShare.Read);
|
FileShare.Read);
|
||||||
@@ -478,12 +478,12 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
|
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if (ioc.StorageFile != null)
|
/*if (ioc.StorageFile != null)
|
||||||
{
|
{*/
|
||||||
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
|
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
|
||||||
}
|
/*}
|
||||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||||
return file.OpenAsync(FileAccess.ReadAndWrite).Result;
|
return file.OpenAsync(FileAccess.ReadAndWrite).Result;*/
|
||||||
#else
|
#else
|
||||||
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
|
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
|
||||||
FileShare.None);
|
FileShare.None);
|
||||||
@@ -502,8 +502,9 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Exists);
|
RaiseIOAccessPreEvent(ioc, IOAccessType.Exists);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if(ioc.IsLocalFile())
|
/*if(ioc.IsLocalFile())
|
||||||
return (FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result != null);
|
return (FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result != null);*/
|
||||||
|
return ioc.StorageFile.IsAvailable;
|
||||||
#else
|
#else
|
||||||
if(ioc.IsLocalFile()) return File.Exists(ioc.Path);
|
if(ioc.IsLocalFile()) return File.Exists(ioc.Path);
|
||||||
#endif
|
#endif
|
||||||
@@ -546,8 +547,8 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if (!ioc.IsLocalFile()) return;
|
if (!ioc.IsLocalFile()) return;
|
||||||
ioc.StorageFile?.DeleteAsync().GetResults();
|
ioc.StorageFile?.DeleteAsync().GetResults();
|
||||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||||
file.DeleteAsync().RunSynchronously();
|
file.DeleteAsync().RunSynchronously();*/
|
||||||
#else
|
#else
|
||||||
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
|
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }
|
||||||
#endif
|
#endif
|
||||||
@@ -587,8 +588,8 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
if (!iocFrom.IsLocalFile()) return;
|
if (!iocFrom.IsLocalFile()) return;
|
||||||
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetResults();
|
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetResults();
|
||||||
var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
|
/*var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
|
||||||
file.MoveAsync(iocTo.Path).RunSynchronously();
|
file.MoveAsync(iocTo.Path).RunSynchronously();*/
|
||||||
#else
|
#else
|
||||||
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
|
if(iocFrom.IsLocalFile()) { File.Move(iocFrom.Path, iocTo.Path); return; }
|
||||||
#endif
|
#endif
|
||||||
@@ -629,18 +630,18 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// using(Stream sIn = IOConnection.OpenRead(iocFrom))
|
// using(Stream sIn = IOConnection.OpenRead(iocFrom))
|
||||||
// {
|
// {
|
||||||
// using(Stream sOut = IOConnection.OpenWrite(iocTo))
|
// using(Stream sOut = IOConnection.OpenWrite(iocTo))
|
||||||
// {
|
// {
|
||||||
// MemUtil.CopyStream(sIn, sOut);
|
// MemUtil.CopyStream(sIn, sOut);
|
||||||
// sOut.Close();
|
// sOut.Close();
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// sIn.Close();
|
// sIn.Close();
|
||||||
// }
|
// }
|
||||||
// DeleteFile(iocFrom);
|
// DeleteFile(iocFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||||
private static bool SendCommand(IOConnectionInfo ioc, string strMethod)
|
private static bool SendCommand(IOConnectionInfo ioc, string strMethod)
|
||||||
@@ -656,8 +657,8 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if !ModernKeePassLibPCL
|
||||||
internal static void DisposeResponse(WebResponse wr, bool bGetStream)
|
internal static void DisposeResponse(WebResponse wr, bool bGetStream)
|
||||||
{
|
{
|
||||||
if(wr == null) return;
|
if(wr == null) return;
|
||||||
|
|
||||||
@@ -674,8 +675,8 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
try { wr.Dispose(); }
|
try { wr.Dispose(); }
|
||||||
catch(Exception) { Debug.Assert(false); }
|
catch(Exception) { Debug.Assert(false); }
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
public static byte[] ReadFile(IOConnectionInfo ioc)
|
public static byte[] ReadFile(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
Stream sIn = null;
|
Stream sIn = null;
|
||||||
MemoryStream ms = null;
|
MemoryStream ms = null;
|
||||||
|
@@ -25,9 +25,9 @@ using System.Net;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Windows.Storage;
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLStorage;
|
using Windows.Storage;
|
||||||
|
//using PCLStorage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLibPCL.Interfaces;
|
using ModernKeePassLibPCL.Interfaces;
|
||||||
|
@@ -24,7 +24,7 @@ using System.IO;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
using PCLCrypto;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
@@ -42,6 +42,7 @@ using ModernKeePassLibPCL.Interfaces;
|
|||||||
using ModernKeePassLibPCL.Keys;
|
using ModernKeePassLibPCL.Keys;
|
||||||
using ModernKeePassLibPCL.Resources;
|
using ModernKeePassLibPCL.Resources;
|
||||||
using ModernKeePassLibPCL.Utility;
|
using ModernKeePassLibPCL.Utility;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
|
||||||
namespace ModernKeePassLibPCL.Serialization
|
namespace ModernKeePassLibPCL.Serialization
|
||||||
{
|
{
|
||||||
@@ -221,13 +222,16 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
msHeader.Dispose();
|
msHeader.Dispose();
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
m_pbHashOfHeader = sha256.HashData(pbHeader);
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
m_pbHashOfHeader = sha256.ComputeHash(pbHeader);
|
m_pbHashOfHeader = sha256.ComputeHash(pbHeader);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ReadHeaderField(BinaryReaderEx brSource)
|
private bool ReadHeaderField(BinaryReaderEx brSource)
|
||||||
{
|
{
|
||||||
@@ -348,14 +352,18 @@ namespace ModernKeePassLibPCL.Serialization
|
|||||||
ms.Write(pKey32, 0, 32);
|
ms.Write(pKey32, 0, 32);
|
||||||
|
|
||||||
#if ModernKeePassLibPCL
|
#if ModernKeePassLibPCL
|
||||||
var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
/*var sha256 = WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
|
||||||
var aesKey = sha256.HashData(ms.ToArray());
|
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
|
#else
|
||||||
SHA256Managed sha256 = new SHA256Managed();
|
SHA256Managed sha256 = new SHA256Managed();
|
||||||
byte[] aesKey = sha256.ComputeHash(ms.ToArray());
|
byte[] aesKey = sha256.ComputeHash(ms.ToArray());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ms.Dispose();
|
ms.Dispose();
|
||||||
Array.Clear(pKey32, 0, 32);
|
Array.Clear(pKey32, 0, 32);
|
||||||
|
|
||||||
if((aesKey == null) || (aesKey.Length != 32))
|
if((aesKey == null) || (aesKey.Length != 32))
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user