mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP Lib 2.37 - databases created by ModernKeepass work fine, but no interoperability...
This commit is contained in:
@@ -253,9 +253,9 @@
|
|||||||
<HintPath>..\packages\Microsoft.Toolkit.Uwp.Notifications.2.0.0\lib\dotnet\Microsoft.Toolkit.Uwp.Notifications.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Toolkit.Uwp.Notifications.2.0.0\lib\dotnet\Microsoft.Toolkit.Uwp.Notifications.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="ModernKeePassLib, Version=2.37.0.2000, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="ModernKeePassLib, Version=2.28.1.4000, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\ModernKeePassLib.2.37.2000\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<Private>True</Private>
|
<HintPath>..\ModernKeePassLib\bin\Debug\ModernKeePassLib.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Splat.2.0.0\lib\Portable-Win81+Wpa81\Splat.dll</HintPath>
|
<HintPath>..\packages\Splat.2.0.0\lib\Portable-Win81+Wpa81\Splat.dll</HintPath>
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<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="Microsoft.Toolkit.Uwp.Notifications" version="2.0.0" targetFramework="win81" />
|
<package id="Microsoft.Toolkit.Uwp.Notifications" version="2.0.0" targetFramework="win81" />
|
||||||
<package id="ModernKeePassLib" version="2.37.2000" targetFramework="win81" />
|
<package id="ModernKeePassLib" version="2.37.3000" targetFramework="win81" />
|
||||||
<package id="NETStandard.Library" version="2.0.1" targetFramework="win81" />
|
<package id="NETStandard.Library" version="2.0.1" targetFramework="win81" />
|
||||||
<package id="Portable.BouncyCastle" version="1.8.1.3" targetFramework="win81" />
|
<package id="Portable.BouncyCastle" version="1.8.1.3" targetFramework="win81" />
|
||||||
<package id="Splat" version="2.0.0" targetFramework="win81" />
|
<package id="Splat" version="2.0.0" targetFramework="win81" />
|
||||||
|
@@ -1,34 +1,33 @@
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System;
|
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||||
|
|
||||||
#if KeePassLib
|
|
||||||
using KeePassLib.Keys;
|
|
||||||
#else
|
|
||||||
using ModernKeePassLib.Keys;
|
using ModernKeePassLib.Keys;
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ModernKeePassLib.Test.Shared.Keys
|
namespace ModernKeePassLib.Test.Shared.Keys
|
||||||
{
|
{
|
||||||
[TestFixture ()]
|
[TestFixture ()]
|
||||||
public class CompositeKeyTests
|
public class CompositeKeyTests
|
||||||
{
|
{
|
||||||
[Test ()]
|
[Test]
|
||||||
public void TestGenerateKey32 ()
|
public void TestGenerateKey32 ()
|
||||||
{
|
{
|
||||||
var originalKey = new byte[32];
|
var originalKey = new byte[32];
|
||||||
var expectedKey = new byte[32] {
|
var expectedKey = new byte[32] {
|
||||||
0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
|
0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
|
||||||
0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
|
0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
|
||||||
0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
|
0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
|
||||||
0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
|
0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
|
||||||
};
|
};
|
||||||
const ulong rounds = 1;
|
const ulong rounds = 1;
|
||||||
|
|
||||||
var composite = new CompositeKey ();
|
var composite = new CompositeKey ();
|
||||||
var key = composite.GenerateKey32 (originalKey, rounds);
|
AesKdf kdf = new AesKdf();
|
||||||
Assert.That (key, Is.Not.Null);
|
KdfParameters p = kdf.GetDefaultParameters();
|
||||||
var keyData = key.ReadData ();
|
p.SetUInt64(AesKdf.ParamRounds, rounds);
|
||||||
Assert.That (keyData, Is.EqualTo (expectedKey));
|
p.SetByteArray(AesKdf.ParamSeed, originalKey);
|
||||||
|
var key = composite.GenerateKey32(p);
|
||||||
|
Assert.That (key, Is.Not.Null);
|
||||||
|
var keyData = key.ReadData ();
|
||||||
|
Assert.That (keyData, Is.EqualTo (expectedKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,6 @@ using System.Diagnostics;
|
|||||||
|
|
||||||
using ModernKeePassLib.Interfaces;
|
using ModernKeePassLib.Interfaces;
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Utility;
|
|
||||||
|
|
||||||
#if KeePassLibSD
|
#if KeePassLibSD
|
||||||
using KeePassLibSD;
|
using KeePassLibSD;
|
||||||
|
@@ -122,17 +122,16 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
|||||||
Array.Copy(pbKey, pbLocalKey, 32);
|
Array.Copy(pbKey, pbLocalKey, 32);
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
AesEngine aes = new AesEngine();
|
var cbc = new CbcBlockCipher(new AesEngine());
|
||||||
CbcBlockCipher cbc = new CbcBlockCipher(aes);
|
var bc = new PaddedBufferedBlockCipher(cbc,
|
||||||
PaddedBufferedBlockCipher bc = new PaddedBufferedBlockCipher(cbc,
|
|
||||||
new Pkcs7Padding());
|
new Pkcs7Padding());
|
||||||
KeyParameter kp = new KeyParameter(pbLocalKey);
|
var kp = new KeyParameter(pbLocalKey);
|
||||||
ParametersWithIV prmIV = new ParametersWithIV(kp, pbLocalIV);
|
var prmIV = new ParametersWithIV(kp, pbLocalIV);
|
||||||
bc.Init(bEncrypt, prmIV);
|
bc.Init(bEncrypt, prmIV);
|
||||||
|
|
||||||
IBufferedCipher cpRead = (bEncrypt ? null : bc);
|
var cpRead = (bEncrypt ? null : bc);
|
||||||
IBufferedCipher cpWrite = (bEncrypt ? bc : null);
|
var cpWrite = (bEncrypt ? bc : null);
|
||||||
return new CipherStream(s, cpRead, cpWrite);
|
return new CipherStream(s, cpRead, cpWrite);
|
||||||
#elif KeePassUAP
|
#elif KeePassUAP
|
||||||
return StandardAesEngineExt.CreateStream(s, bEncrypt, pbLocalKey, pbLocalIV);
|
return StandardAesEngineExt.CreateStream(s, bEncrypt, pbLocalKey, pbLocalIV);
|
||||||
#else
|
#else
|
||||||
|
@@ -19,18 +19,20 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
using ModernKeePassLib.Utility;
|
|
||||||
using Windows.Security.Cryptography.Core;
|
using Windows.Security.Cryptography.Core;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.IO;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
|
||||||
using ModernKeePassLib.Native;
|
|
||||||
|
|
||||||
|
using ModernKeePassLib.Native;
|
||||||
|
using ModernKeePassLib.Utility;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Cryptography
|
namespace ModernKeePassLib.Cryptography
|
||||||
{
|
{
|
||||||
@@ -44,7 +46,7 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
private byte[] m_pbEntropyPool = new byte[64];
|
private byte[] m_pbEntropyPool = new byte[64];
|
||||||
private ulong m_uCounter;
|
private ulong m_uCounter;
|
||||||
#if !ModernKeePassLib
|
#if !ModernKeePassLib
|
||||||
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
|
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
|
||||||
#endif
|
#endif
|
||||||
private ulong m_uGeneratedBytesCount = 0;
|
private ulong m_uGeneratedBytesCount = 0;
|
||||||
|
|
||||||
|
@@ -20,8 +20,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
using Windows.Security.Cryptography.Core;
|
using Windows.Security.Cryptography.Core;
|
||||||
|
#elif !KeePassUAP
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLib.Cryptography.Cipher;
|
using ModernKeePassLib.Cryptography.Cipher;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
|
|
||||||
|
@@ -22,13 +22,17 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using ModernKeePassLib.Cryptography.Hash;
|
||||||
|
#if ModernKeePassLib
|
||||||
|
using Org.BouncyCastle.Asn1.Pkcs;
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
using Windows.Security.Cryptography.Core;
|
using Windows.Security.Cryptography.Core;
|
||||||
using ModernKeePassLib.Cryptography.Hash;
|
#elif !KeePassUAP
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLib.Native;
|
using ModernKeePassLib.Native;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Org.BouncyCastle.Asn1.Pkcs;
|
|
||||||
|
|
||||||
namespace ModernKeePassLib.Cryptography
|
namespace ModernKeePassLib.Cryptography
|
||||||
{
|
{
|
||||||
|
@@ -21,17 +21,19 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
using Windows.Security.Cryptography.Core;
|
using Windows.Security.Cryptography.Core;
|
||||||
using Org.BouncyCastle.Crypto;
|
using Org.BouncyCastle.Crypto;
|
||||||
using Org.BouncyCastle.Crypto.Digests;
|
using Org.BouncyCastle.Crypto.Digests;
|
||||||
#else
|
using Org.BouncyCastle.Crypto.Tls;
|
||||||
|
#elif !KeePassUAP
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Org.BouncyCastle.Crypto.Tls;
|
|
||||||
|
|
||||||
namespace ModernKeePassLib.Cryptography
|
namespace ModernKeePassLib.Cryptography
|
||||||
{
|
{
|
||||||
@@ -39,7 +41,7 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
{
|
{
|
||||||
private readonly Stream m_sBaseStream;
|
private readonly Stream m_sBaseStream;
|
||||||
private readonly bool m_bWriting;
|
private readonly bool m_bWriting;
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
//private ICryptoTransform m_hash;
|
//private ICryptoTransform m_hash;
|
||||||
//private CryptographicHash m_hash;
|
//private CryptographicHash m_hash;
|
||||||
private IDigest m_hash;
|
private IDigest m_hash;
|
||||||
@@ -81,20 +83,19 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
//public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm? hashAlgorithm)
|
public HashingStreamEx(Stream sBaseStream, bool bWriting, IDigest 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) throw new ArgumentNullException("sBaseStream");
|
if(sBaseStream == null) throw new ArgumentNullException("sBaseStream");
|
||||||
|
|
||||||
m_sBaseStream = sBaseStream;
|
m_sBaseStream = sBaseStream;
|
||||||
m_bWriting = bWriting;
|
m_bWriting = bWriting;
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
//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();
|
//m_hash = HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithmNames.Sha256).CreateHash();
|
||||||
m_hash = new Sha256Digest();
|
m_hash = hashAlgorithm ?? new Sha256Digest();
|
||||||
#elif !KeePassLibSD
|
#elif !KeePassLibSD
|
||||||
m_hash = (hashAlgorithm ?? new SHA256Managed());
|
m_hash = (hashAlgorithm ?? new SHA256Managed());
|
||||||
#else // KeePassLibSD
|
#else // KeePassLibSD
|
||||||
@@ -108,46 +109,48 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
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 ModernKeePassLib
|
||||||
|
#else
|
||||||
|
if(!m_hash.CanReuseTransform || !m_hash.CanTransformMultipleBlocks)
|
||||||
{
|
{
|
||||||
Debug.Assert(false);
|
Debug.Assert(false);
|
||||||
m_hash = null;
|
m_hash = null;
|
||||||
}*/
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ModernKeePassLib || KeePassRT
|
protected override void Dispose(bool disposing)
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (!disposing) return;
|
|
||||||
#else
|
|
||||||
public override void Close()
|
|
||||||
{
|
{
|
||||||
#endif
|
if(disposing)
|
||||||
if (m_hash != null)
|
{
|
||||||
{
|
if(m_hash != null)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
//m_hash.TransformFinalBlock(new byte[0], 0, 0);
|
{
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
//m_pbFinalHash = (m_hash as CryptographicHash).GetValueAndReset ();
|
//m_pbFinalHash = (m_hash as CryptographicHash).GetValueAndReset ();
|
||||||
//CryptographicBuffer.CopyToByteArray(m_hash.GetValueAndReset(), out m_pbFinalHash);
|
//CryptographicBuffer.CopyToByteArray(m_hash.GetValueAndReset(), out m_pbFinalHash);
|
||||||
m_pbFinalHash = new byte[32];
|
m_pbFinalHash = new byte[32];
|
||||||
m_hash.DoFinal(m_pbFinalHash, 0);
|
m_hash.DoFinal(m_pbFinalHash, 0);
|
||||||
m_hash.Reset();
|
m_hash.Reset();
|
||||||
#else
|
#else
|
||||||
m_pbFinalHash = m_hash.Hash;
|
m_hash.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
|
||||||
|
|
||||||
|
m_pbFinalHash = m_hash.Hash;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch(Exception) { Debug.Assert(false); }
|
||||||
{
|
|
||||||
Debug.Assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
base.Dispose(disposing);
|
m_hash = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override void Flush()
|
m_sBaseStream.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Flush()
|
||||||
{
|
{
|
||||||
m_sBaseStream.Flush();
|
m_sBaseStream.Flush();
|
||||||
}
|
}
|
||||||
@@ -181,8 +184,11 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((m_hash != null) && (nRead > 0))
|
if((m_hash != null) && (nRead > 0))
|
||||||
//m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);
|
#if ModernKeePassLib
|
||||||
m_hash.BlockUpdate(pbBuffer, nOffset, nRead);
|
m_hash.BlockUpdate(pbBuffer, nOffset, nRead);
|
||||||
|
#else
|
||||||
|
m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
||||||
@@ -201,8 +207,11 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((m_hash != null) && (nCount > 0))
|
if((m_hash != null) && (nCount > 0))
|
||||||
//m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);
|
#if ModernKeePassLib
|
||||||
m_hash.BlockUpdate(pbBuffer, nOffset, nCount);
|
m_hash.BlockUpdate(pbBuffer, nOffset, nCount);
|
||||||
|
#else
|
||||||
|
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
||||||
|
@@ -19,18 +19,18 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
using Windows.Security.Cryptography.Core;
|
||||||
|
#elif !KeePassUAP
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
|
|
||||||
#if (!KeePassLibSD && !KeePassRT)
|
#if !KeePassLibSD
|
||||||
namespace ModernKeePassLib.Cryptography
|
namespace ModernKeePassLib.Cryptography
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -47,11 +47,15 @@ namespace ModernKeePassLib.Cryptography
|
|||||||
byte[] pbText = MemUtil.UInt64ToBytes(uFactor);
|
byte[] pbText = MemUtil.UInt64ToBytes(uFactor);
|
||||||
Array.Reverse(pbText); // To big-endian
|
Array.Reverse(pbText); // To big-endian
|
||||||
|
|
||||||
|
#if ModernKeePassLib
|
||||||
var hsha1 = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1).CreateHash(CryptographicBuffer.CreateFromByteArray(pbSecret));
|
var hsha1 = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1).CreateHash(CryptographicBuffer.CreateFromByteArray(pbSecret));
|
||||||
hsha1.Append(CryptographicBuffer.CreateFromByteArray(pbText));
|
hsha1.Append(CryptographicBuffer.CreateFromByteArray(pbText));
|
||||||
byte[] pbHash;
|
byte[] pbHash;
|
||||||
CryptographicBuffer.CopyToByteArray(hsha1.GetValueAndReset(), out pbHash);
|
CryptographicBuffer.CopyToByteArray(hsha1.GetValueAndReset(), out pbHash);
|
||||||
|
#else
|
||||||
|
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
|
||||||
|
byte[] pbHash = hsha1.ComputeHash(pbText);
|
||||||
|
#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;
|
||||||
|
@@ -114,7 +114,7 @@ namespace ModernKeePassLib.Cryptography.KeyDerivation
|
|||||||
ctx.LaneLength = ctx.SegmentLength * NbSyncPoints;
|
ctx.LaneLength = ctx.SegmentLength * NbSyncPoints;
|
||||||
|
|
||||||
Debug.Assert(NbBlockSize == (NbBlockSizeInQW *
|
Debug.Assert(NbBlockSize == (NbBlockSizeInQW *
|
||||||
#if KeePassUAP
|
#if ModernKeePassLib || KeePassUAP
|
||||||
(ulong)Marshal.SizeOf<ulong>()
|
(ulong)Marshal.SizeOf<ulong>()
|
||||||
#else
|
#else
|
||||||
(ulong)Marshal.SizeOf(typeof(ulong))
|
(ulong)Marshal.SizeOf(typeof(ulong))
|
||||||
|
@@ -21,9 +21,14 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Diagnostics;
|
|
||||||
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
using Windows.Security.Cryptography.Core;
|
using Windows.Security.Cryptography.Core;
|
||||||
|
#elif !KeePassUAP
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
|
|
||||||
@@ -88,7 +93,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
|||||||
byte[] pbHash;
|
byte[] pbHash;
|
||||||
CryptographicBuffer.CopyToByteArray(h, out pbHash);
|
CryptographicBuffer.CopyToByteArray(h, out pbHash);
|
||||||
MemUtil.XorArray(pbHash, 0, pbKey, 0, pbHash.Length);
|
MemUtil.XorArray(pbHash, 0, pbKey, 0, pbHash.Length);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using(SHA512Managed h = new SHA512Managed())
|
using(SHA512Managed h = new SHA512Managed())
|
||||||
{
|
{
|
||||||
|
@@ -265,7 +265,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
|||||||
else pcs.Add(ch);
|
else pcs.Add(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.Clear(vChars, 0, vChars.Length);
|
MemUtil.ZeroArray<char>(vChars);
|
||||||
MemUtil.ZeroByteArray(pbUtf8);
|
MemUtil.ZeroByteArray(pbUtf8);
|
||||||
return pp;
|
return pp;
|
||||||
}
|
}
|
||||||
|
@@ -18,32 +18,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.Text;
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
|
||||||
#if ModernKeePassLib
|
|
||||||
using Windows.Security.Cryptography;
|
|
||||||
#else
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KeePassRT
|
using ModernKeePassLib.Cryptography;
|
||||||
using Org.BouncyCastle.Crypto.Engines;
|
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||||
using Org.BouncyCastle.Crypto.Parameters;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using ModernKeePassLib.Native;
|
|
||||||
using ModernKeePassLib.Resources;
|
using ModernKeePassLib.Resources;
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
using Windows.Storage.Streams;
|
|
||||||
using ModernKeePassLib.Cryptography;
|
|
||||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
|
||||||
using Org.BouncyCastle.Crypto.Engines;
|
|
||||||
using KdfParameters = Org.BouncyCastle.Crypto.Parameters.KdfParameters;
|
|
||||||
|
|
||||||
namespace ModernKeePassLib.Keys
|
namespace ModernKeePassLib.Keys
|
||||||
{
|
{
|
||||||
@@ -119,7 +102,6 @@ namespace ModernKeePassLib.Keys
|
|||||||
return m_vUserKeys.Remove(pKey);
|
return m_vUserKeys.Remove(pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !ModernKeePassLib && !KeePassRT
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test whether the composite key contains a specific type of
|
/// Test whether the composite key contains a specific type of
|
||||||
/// user keys (password, key file, ...). If at least one user
|
/// user keys (password, key file, ...). If at least one user
|
||||||
@@ -137,7 +119,7 @@ namespace ModernKeePassLib.Keys
|
|||||||
{
|
{
|
||||||
if(pKey == null) { Debug.Assert(false); continue; }
|
if(pKey == null) { Debug.Assert(false); continue; }
|
||||||
|
|
||||||
#if KeePassUAP
|
#if ModernKeePassLib || KeePassUAP
|
||||||
if(pKey.GetType() == tUserKeyType)
|
if(pKey.GetType() == tUserKeyType)
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
@@ -164,7 +146,7 @@ namespace ModernKeePassLib.Keys
|
|||||||
{
|
{
|
||||||
if(pKey == null) { Debug.Assert(false); continue; }
|
if(pKey == null) { Debug.Assert(false); continue; }
|
||||||
|
|
||||||
#if KeePassUAP
|
#if ModernKeePassLib || KeePassUAP
|
||||||
if(pKey.GetType() == tUserKeyType)
|
if(pKey.GetType() == tUserKeyType)
|
||||||
return pKey;
|
return pKey;
|
||||||
#else
|
#else
|
||||||
@@ -175,7 +157,6 @@ namespace ModernKeePassLib.Keys
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the composite key from the supplied user key sources (password,
|
/// Creates the composite key from the supplied user key sources (password,
|
||||||
@@ -236,7 +217,7 @@ namespace ModernKeePassLib.Keys
|
|||||||
if(pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32");
|
if(pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32");
|
||||||
|
|
||||||
AesKdf kdf = new AesKdf();
|
AesKdf kdf = new AesKdf();
|
||||||
var p = kdf.GetDefaultParameters();
|
KdfParameters p = kdf.GetDefaultParameters();
|
||||||
p.SetUInt64(AesKdf.ParamRounds, uNumRounds);
|
p.SetUInt64(AesKdf.ParamRounds, uNumRounds);
|
||||||
p.SetByteArray(AesKdf.ParamSeed, pbKeySeed32);
|
p.SetByteArray(AesKdf.ParamSeed, pbKeySeed32);
|
||||||
|
|
||||||
@@ -246,7 +227,7 @@ namespace ModernKeePassLib.Keys
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a 32-byte (256-bit) key from the composite key.
|
/// Generate a 32-byte (256-bit) key from the composite key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ProtectedBinary GenerateKey32(Cryptography.KeyDerivation.KdfParameters p)
|
public ProtectedBinary GenerateKey32(KdfParameters p)
|
||||||
{
|
{
|
||||||
if(p == null) { Debug.Assert(false); throw new ArgumentNullException("p"); }
|
if(p == null) { Debug.Assert(false); throw new ArgumentNullException("p"); }
|
||||||
|
|
||||||
|
@@ -19,18 +19,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
#if ModernKeePassLib
|
using System.Text;
|
||||||
using Windows.Security.Cryptography;
|
|
||||||
#else
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using ModernKeePassLib.Security;
|
|
||||||
using ModernKeePassLib.Utility;
|
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
using ModernKeePassLib.Cryptography;
|
using ModernKeePassLib.Cryptography;
|
||||||
|
using ModernKeePassLib.Security;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Keys
|
namespace ModernKeePassLib.Keys
|
||||||
{
|
{
|
||||||
|
@@ -18,26 +18,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
using ModernKeePassLib.Cryptography;
|
using ModernKeePassLib.Cryptography;
|
||||||
using ModernKeePassLib.Resources;
|
using ModernKeePassLib.Resources;
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Serialization;
|
using ModernKeePassLib.Serialization;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
|
|
||||||
namespace ModernKeePassLib.Keys
|
namespace ModernKeePassLib.Keys
|
||||||
{
|
{
|
||||||
|
@@ -18,17 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
#if ModernKeePassLib
|
using System.Text;
|
||||||
using Windows.Security.Cryptography;
|
|
||||||
#else
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
using ModernKeePassLib.Cryptography;
|
using ModernKeePassLib.Cryptography;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Keys
|
namespace ModernKeePassLib.Keys
|
||||||
|
@@ -21,8 +21,9 @@ using System;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
|
||||||
|
#if ModernKeePassLib
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
#if !KeePassUAP
|
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ namespace ModernKeePassLib.Keys
|
|||||||
strUserDir += PwDefs.ShortProductName;
|
strUserDir += PwDefs.ShortProductName;
|
||||||
#if !ModernKeePassLib
|
#if !ModernKeePassLib
|
||||||
|
|
||||||
if (bCreate && !Directory.Exists(strUserDir))
|
if(bCreate && !Directory.Exists(strUserDir))
|
||||||
Directory.CreateDirectory(strUserDir);
|
Directory.CreateDirectory(strUserDir);
|
||||||
#endif
|
#endif
|
||||||
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
|
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
|
||||||
@@ -121,9 +122,9 @@ namespace ModernKeePassLib.Keys
|
|||||||
fileStream.Read(pbProtectedKey, 0, (int)fileStream.Length);
|
fileStream.Read(pbProtectedKey, 0, (int)fileStream.Length);
|
||||||
fileStream.Dispose();
|
fileStream.Dispose();
|
||||||
#else
|
#else
|
||||||
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
|
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
|
||||||
#endif
|
#endif
|
||||||
pbKey = ProtectedData.Unprotect(pbProtectedKey, m_pbEntropy,
|
pbKey = ProtectedData.Unprotect(pbProtectedKey, m_pbEntropy,
|
||||||
DataProtectionScope.CurrentUser);
|
DataProtectionScope.CurrentUser);
|
||||||
}
|
}
|
||||||
catch(Exception)
|
catch(Exception)
|
||||||
@@ -133,7 +134,7 @@ namespace ModernKeePassLib.Keys
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return pbKey;
|
return pbKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] CreateUserKey()
|
private static byte[] CreateUserKey()
|
||||||
@@ -151,10 +152,10 @@ namespace ModernKeePassLib.Keys
|
|||||||
fileStream.Write(pbProtectedKey, 0, (int)fileStream.Length);
|
fileStream.Write(pbProtectedKey, 0, (int)fileStream.Length);
|
||||||
fileStream.Dispose();
|
fileStream.Dispose();
|
||||||
#else
|
#else
|
||||||
File.WriteAllBytes(strFilePath, pbProtectedKey);
|
File.WriteAllBytes(strFilePath, pbProtectedKey);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
byte[] pbKey = LoadUserKey(true);
|
byte[] pbKey = LoadUserKey(true);
|
||||||
Debug.Assert(MemUtil.ArraysEqual(pbKey, pbRandomKey));
|
Debug.Assert(MemUtil.ArraysEqual(pbKey, pbRandomKey));
|
||||||
|
|
||||||
MemUtil.ZeroByteArray(pbRandomKey);
|
MemUtil.ZeroByteArray(pbRandomKey);
|
||||||
|
@@ -125,7 +125,8 @@
|
|||||||
<Compile Include="Serialization\IOConnectionInfo.cs" />
|
<Compile Include="Serialization\IOConnectionInfo.cs" />
|
||||||
<Compile Include="Serialization\OldFormatException.cs" />
|
<Compile Include="Serialization\OldFormatException.cs" />
|
||||||
<Compile Include="Utility\AppLogEx.cs" />
|
<Compile Include="Utility\AppLogEx.cs" />
|
||||||
<Compile Include="Utility\GfxUtil.cs" />
|
<None Include="Utility\GfxUtil.cs" />
|
||||||
|
<Compile Include="Utility\GfxUtil.PCL.cs" />
|
||||||
<Compile Include="Utility\MemUtil.cs" />
|
<Compile Include="Utility\MemUtil.cs" />
|
||||||
<Compile Include="Cryptography\PasswordGenerator\PwGenerator.cs" />
|
<Compile Include="Cryptography\PasswordGenerator\PwGenerator.cs" />
|
||||||
<Compile Include="Utility\MonoWorkaround.PCL.cs" />
|
<Compile Include="Utility\MonoWorkaround.PCL.cs" />
|
||||||
@@ -173,6 +174,7 @@
|
|||||||
<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>
|
||||||
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,16 +19,15 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
#if ModernKeePassLib
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#else
|
|
||||||
using System.Threading;
|
|
||||||
#endif
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
#if ModernKeePassLib
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
using System.Runtime.InteropServices.WindowsRuntime;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
|
#endif
|
||||||
using ModernKeePassLib.Cryptography;
|
using ModernKeePassLib.Cryptography;
|
||||||
using ModernKeePassLib.Resources;
|
using ModernKeePassLib.Resources;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
|
@@ -29,6 +29,7 @@ using ModernKeePassLib.Resources;
|
|||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Org.BouncyCastle.Crypto.Digests;
|
using Org.BouncyCastle.Crypto.Digests;
|
||||||
using Org.BouncyCastle.Crypto.Macs;
|
using Org.BouncyCastle.Crypto.Macs;
|
||||||
|
using Org.BouncyCastle.Crypto.Parameters;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Serialization
|
namespace ModernKeePassLib.Serialization
|
||||||
{
|
{
|
||||||
@@ -244,17 +245,18 @@ namespace ModernKeePassLib.Serialization
|
|||||||
byte[] pbCmpHmac;
|
byte[] pbCmpHmac;
|
||||||
byte[] pbBlockKey = GetHmacKey64(m_pbKey, m_uBlockIndex);
|
byte[] pbBlockKey = GetHmacKey64(m_pbKey, m_uBlockIndex);
|
||||||
|
|
||||||
/*#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
var h = new HMac(new Sha256Digest());
|
var h = new HMac(new Sha256Digest());
|
||||||
|
h.Init(new KeyParameter(pbBlockKey));
|
||||||
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
|
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
|
||||||
h.BlockUpdate(pbBlockSize, 0, pbBlockSize.Length);
|
h.BlockUpdate(pbBlockSize, 0, pbBlockSize.Length);
|
||||||
if (m_pbBuffer.Length > 0)
|
if (m_pbBuffer.Length > 0)
|
||||||
h.BlockUpdate(m_pbBuffer, 0, m_pbBuffer.Length);
|
h.BlockUpdate(m_pbBuffer, 0, m_pbBuffer.Length);
|
||||||
|
pbCmpHmac = MemUtil.EmptyByteArray;
|
||||||
h.DoFinal(pbCmpHmac, 0);
|
h.DoFinal(pbCmpHmac, 0);
|
||||||
h.Reset();
|
h.Reset();
|
||||||
#else*/
|
#else
|
||||||
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
|
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
|
||||||
{
|
{
|
||||||
h.TransformBlock(pbBlockIndex, 0, pbBlockIndex.Length,
|
h.TransformBlock(pbBlockIndex, 0, pbBlockIndex.Length,
|
||||||
pbBlockIndex, 0);
|
pbBlockIndex, 0);
|
||||||
@@ -269,7 +271,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
pbCmpHmac = h.Hash;
|
pbCmpHmac = h.Hash;
|
||||||
}
|
}
|
||||||
//#endif
|
#endif
|
||||||
MemUtil.ZeroByteArray(pbBlockKey);
|
MemUtil.ZeroByteArray(pbBlockKey);
|
||||||
|
|
||||||
if(!MemUtil.ArraysEqual(pbCmpHmac, pbStoredHmac))
|
if(!MemUtil.ArraysEqual(pbCmpHmac, pbStoredHmac))
|
||||||
@@ -317,16 +319,18 @@ namespace ModernKeePassLib.Serialization
|
|||||||
byte[] pbBlockHmac;
|
byte[] pbBlockHmac;
|
||||||
byte[] pbBlockKey = GetHmacKey64(m_pbKey, m_uBlockIndex);
|
byte[] pbBlockKey = GetHmacKey64(m_pbKey, m_uBlockIndex);
|
||||||
|
|
||||||
/*#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
var h = new HMac(new Sha256Digest());
|
var h = new HMac(new Sha256Digest());
|
||||||
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
|
h.Init(new KeyParameter(pbBlockKey));
|
||||||
|
h.BlockUpdate(pbBlockIndex, 0, pbBlockIndex.Length);
|
||||||
h.BlockUpdate(pbBlockSize, 0, pbBlockSize.Length);
|
h.BlockUpdate(pbBlockSize, 0, pbBlockSize.Length);
|
||||||
if (m_pbBuffer.Length > 0)
|
if (cbBlockSize > 0)
|
||||||
h.BlockUpdate(m_pbBuffer, 0, m_pbBuffer.Length);
|
h.BlockUpdate(m_pbBuffer, 0, cbBlockSize);
|
||||||
|
|
||||||
h.DoFinal(pbBlockHmac, 0);
|
pbBlockHmac = MemUtil.EmptyByteArray;
|
||||||
|
h.DoFinal(pbBlockHmac, 0);
|
||||||
h.Reset();
|
h.Reset();
|
||||||
#else*/
|
#else
|
||||||
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
|
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
|
||||||
{
|
{
|
||||||
h.TransformBlock(pbBlockIndex, 0, pbBlockIndex.Length,
|
h.TransformBlock(pbBlockIndex, 0, pbBlockIndex.Length,
|
||||||
@@ -341,7 +345,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
pbBlockHmac = h.Hash;
|
pbBlockHmac = h.Hash;
|
||||||
}
|
}
|
||||||
//#endif
|
#endif
|
||||||
MemUtil.ZeroByteArray(pbBlockKey);
|
MemUtil.ZeroByteArray(pbBlockKey);
|
||||||
|
|
||||||
MemUtil.Write(m_sBase, pbBlockHmac);
|
MemUtil.Write(m_sBase, pbBlockHmac);
|
||||||
|
@@ -1,13 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
@@ -19,24 +18,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Diagnostics;
|
using System.Reflection;
|
||||||
using Windows.Storage.Streams;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ModernKeePassLib.Native;
|
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassUAP)
|
||||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
|
||||||
using System.Net.Cache;
|
using System.Net.Cache;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !ModernKeePassLib && !KeePassRT
|
#if !ModernKeePassLib && !KeePassUAP
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
|
using Windows.Storage.Streams;
|
||||||
#endif
|
#endif
|
||||||
|
using ModernKeePassLib.Native;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
|
|
||||||
namespace ModernKeePassLib.Serialization
|
namespace ModernKeePassLib.Serialization
|
||||||
@@ -44,10 +46,17 @@ namespace ModernKeePassLib.Serialization
|
|||||||
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
#if (!ModernKeePassLib && !KeePassLibSD && !KeePassRT)
|
||||||
internal sealed class IOWebClient : WebClient
|
internal sealed class IOWebClient : WebClient
|
||||||
{
|
{
|
||||||
|
private IOConnectionInfo m_ioc;
|
||||||
|
|
||||||
|
public IOWebClient(IOConnectionInfo ioc) : base()
|
||||||
|
{
|
||||||
|
m_ioc = ioc;
|
||||||
|
}
|
||||||
|
|
||||||
protected override WebRequest GetWebRequest(Uri address)
|
protected override WebRequest GetWebRequest(Uri address)
|
||||||
{
|
{
|
||||||
WebRequest request = base.GetWebRequest(address);
|
WebRequest request = base.GetWebRequest(address);
|
||||||
IOConnection.ConfigureWebRequest(request);
|
IOConnection.ConfigureWebRequest(request, m_ioc);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -581,7 +590,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
new Uri(ioc.Path)));
|
new Uri(ioc.Path)));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public static Stream OpenRead(IOConnectionInfo ioc)
|
public static Stream OpenRead(IOConnectionInfo ioc)
|
||||||
{
|
{
|
||||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
|
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
|
||||||
|
|
||||||
@@ -700,7 +709,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
catch(Exception) { Debug.Assert(false); }
|
catch(Exception) { Debug.Assert(false); }
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Xml.Serialization;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml.Serialization;
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
//using PCLStorage;
|
//using PCLStorage;
|
||||||
@@ -338,13 +337,13 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
public StorageFile StorageFile { get; set; }
|
public StorageFile StorageFile { get; set; }
|
||||||
|
|
||||||
public async Task<bool> CanProbablyAccess()
|
public bool CanProbablyAccess()
|
||||||
{
|
{
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
if (IsLocalFile())
|
if (IsLocalFile())
|
||||||
{
|
{
|
||||||
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
|
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
|
||||||
var file = await StorageFile.GetFileFromPathAsync(m_strUrl);
|
var file = StorageFile.GetFileFromPathAsync(m_strUrl).GetAwaiter().GetResult();
|
||||||
return file != null;
|
return file != null;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@@ -25,8 +25,6 @@ using System.Text;
|
|||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.IO;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
using ModernKeePassLib;
|
using ModernKeePassLib;
|
||||||
using ModernKeePassLib.Collections;
|
using ModernKeePassLib.Collections;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,18 +17,22 @@
|
|||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// #define KDBX_BENCHMARK
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
|
using Windows.Storage.Streams;
|
||||||
#else
|
#else
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
#if !KeePassLibSD
|
#if !KeePassLibSD
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
@@ -42,8 +46,6 @@ using ModernKeePassLib.Interfaces;
|
|||||||
using ModernKeePassLib.Keys;
|
using ModernKeePassLib.Keys;
|
||||||
using ModernKeePassLib.Resources;
|
using ModernKeePassLib.Resources;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
using Windows.Storage.Streams;
|
|
||||||
using ModernKeePassLib.Collections;
|
using ModernKeePassLib.Collections;
|
||||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||||
using ModernKeePassLib.Security;
|
using ModernKeePassLib.Security;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,23 +19,23 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Security.Cryptography;
|
using Windows.Security.Cryptography;
|
||||||
#else
|
#else
|
||||||
|
using System.Drawing;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#endif
|
#endif
|
||||||
using System.Drawing;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
#if !KeePassLibSD
|
#if KeePassLibSD
|
||||||
using System.IO.Compression;
|
|
||||||
#else
|
|
||||||
using KeePassLibSD;
|
using KeePassLibSD;
|
||||||
|
#else
|
||||||
|
using System.IO.Compression;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLib.Collections;
|
using ModernKeePassLib.Collections;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,20 +19,17 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using Windows.Security.Cryptography;
|
using System.Text;
|
||||||
using Windows.Security.Cryptography.Core;
|
using System.Xml;
|
||||||
#if !KeePassLibSD
|
|
||||||
using System.IO.Compression;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
|
using Windows.Security.Cryptography;
|
||||||
|
using Windows.Security.Cryptography.Core;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ModernKeePassLib.Collections;
|
using ModernKeePassLib.Collections;
|
||||||
@@ -207,11 +204,7 @@ namespace ModernKeePassLib.Serialization
|
|||||||
private PwDatabase m_pwDatabase; // Not null, see constructor
|
private PwDatabase m_pwDatabase; // Not null, see constructor
|
||||||
private bool m_bUsedOnce = false;
|
private bool m_bUsedOnce = false;
|
||||||
|
|
||||||
#if ModernKeePassLib
|
|
||||||
private XmlWriter m_xmlWriter = null;
|
private XmlWriter m_xmlWriter = null;
|
||||||
#else
|
|
||||||
private XmlTextWriter m_xmlWriter = null;
|
|
||||||
#endif
|
|
||||||
private CryptoRandomStream m_randomStream = null;
|
private CryptoRandomStream m_randomStream = null;
|
||||||
private KdbxFormat m_format = KdbxFormat.Default;
|
private KdbxFormat m_format = KdbxFormat.Default;
|
||||||
private IStatusLogger m_slLogger = null;
|
private IStatusLogger m_slLogger = null;
|
||||||
@@ -403,12 +396,12 @@ namespace ModernKeePassLib.Serialization
|
|||||||
.HashData(CryptographicBuffer.CreateFromByteArray(pbCmp));
|
.HashData(CryptographicBuffer.CreateFromByteArray(pbCmp));
|
||||||
CryptographicBuffer.CopyToByteArray(h, out pbHmacKey64);
|
CryptographicBuffer.CopyToByteArray(h, out pbHmacKey64);
|
||||||
#else
|
#else
|
||||||
using(SHA512Managed h = new SHA512Managed())
|
using(SHA512Managed h = new SHA512Managed())
|
||||||
{
|
{
|
||||||
pbHmacKey64 = h.ComputeHash(pbCmp);
|
pbHmacKey64 = h.ComputeHash(pbCmp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
finally { MemUtil.ZeroByteArray(pbCmp); }
|
finally { MemUtil.ZeroByteArray(pbCmp); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,11 +452,11 @@ namespace ModernKeePassLib.Serialization
|
|||||||
byte[] pbHeaderHmac;
|
byte[] pbHeaderHmac;
|
||||||
byte[] pbBlockKey = HmacBlockStream.GetHmacKey64(
|
byte[] pbBlockKey = HmacBlockStream.GetHmacKey64(
|
||||||
pbKey, ulong.MaxValue);
|
pbKey, ulong.MaxValue);
|
||||||
using (HMACSHA256 h = new HMACSHA256(pbBlockKey))
|
using(HMACSHA256 h = new HMACSHA256(pbBlockKey))
|
||||||
{
|
{
|
||||||
pbHeaderHmac = h.ComputeHash(pbHeader);
|
pbHeaderHmac = h.ComputeHash(pbHeader);
|
||||||
}
|
}
|
||||||
MemUtil.ZeroByteArray(pbBlockKey);
|
MemUtil.ZeroByteArray(pbBlockKey);
|
||||||
|
|
||||||
return pbHeaderHmac;
|
return pbHeaderHmac;
|
||||||
}
|
}
|
||||||
@@ -522,10 +515,9 @@ namespace ModernKeePassLib.Serialization
|
|||||||
|
|
||||||
if(!string.IsNullOrEmpty(strExt)) strPath += "." + strExt;
|
if(!string.IsNullOrEmpty(strExt)) strPath += "." + strExt;
|
||||||
|
|
||||||
++iTry;
|
++iTry;
|
||||||
}
|
}
|
||||||
#if ModernKeePassLib
|
#if ModernKeePassLib
|
||||||
//while(FileSystem.Current.GetFileFromPathAsync(strPath).Result != null);
|
|
||||||
while (StorageFile.GetFileFromPathAsync(strPath).GetResults() != null);
|
while (StorageFile.GetFileFromPathAsync(strPath).GetResults() != null);
|
||||||
#else
|
#else
|
||||||
while(File.Exists(strPath));
|
while(File.Exists(strPath));
|
||||||
|
22
ModernKeePassLib/Utility/GfxUtil.PCL.cs
Normal file
22
ModernKeePassLib/Utility/GfxUtil.PCL.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Splat;
|
||||||
|
|
||||||
|
namespace ModernKeePassLib.Utility
|
||||||
|
{
|
||||||
|
public class GfxUtil
|
||||||
|
{
|
||||||
|
public static async Task<IBitmap> LoadImage(byte[] pb)
|
||||||
|
{
|
||||||
|
return await ScaleImage(pb, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<IBitmap> ScaleImage(byte[] pb, int? w, int? h)
|
||||||
|
{
|
||||||
|
using (var ms = new MemoryStream(pb, false))
|
||||||
|
{
|
||||||
|
return await BitmapLoader.Current.Load(ms, w, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
KeePass Password Safe - The Open-Source Password Manager
|
KeePass Password Safe - The Open-Source Password Manager
|
||||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
Copyright (C) 2003-2017 Dominik Reichl <dominik.reichl@t-online.de>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,16 +19,15 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
#if ModernKeePassLib
|
using System.Text;
|
||||||
using Splat;
|
|
||||||
#else
|
#if !KeePassUAP
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
#endif
|
#endif
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ModernKeePassLib.Utility
|
namespace ModernKeePassLib.Utility
|
||||||
{
|
{
|
||||||
@@ -68,19 +67,6 @@ namespace ModernKeePassLib.Utility
|
|||||||
try { return Image.FromStream(ms); }
|
try { return Image.FromStream(ms); }
|
||||||
finally { ms.Close(); }
|
finally { ms.Close(); }
|
||||||
}
|
}
|
||||||
#elif ModernKeePassLib
|
|
||||||
public static async Task<IBitmap> LoadImage(byte[] pb)
|
|
||||||
{
|
|
||||||
return await ScaleImage(pb, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<IBitmap> ScaleImage(byte[] pb, int? w, int? h)
|
|
||||||
{
|
|
||||||
using (var ms = new MemoryStream(pb, false))
|
|
||||||
{
|
|
||||||
return await BitmapLoader.Current.Load(ms, w, h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
public static Image LoadImage(byte[] pb)
|
public static Image LoadImage(byte[] pb)
|
||||||
{
|
{
|
||||||
@@ -437,9 +423,8 @@ namespace ModernKeePassLib.Utility
|
|||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
#endif // !KeePassLibSD
|
#endif // !KeePassLibSD
|
||||||
#endif // KeePassUAP
|
#endif // KeePassUAP
|
||||||
#if ModernKeePassLib
|
|
||||||
#else
|
internal static string ImageToDataUri(Image img)
|
||||||
internal static string ImageToDataUri(Image img)
|
|
||||||
{
|
{
|
||||||
if(img == null) { Debug.Assert(false); return string.Empty; }
|
if(img == null) { Debug.Assert(false); return string.Empty; }
|
||||||
|
|
||||||
@@ -452,6 +437,5 @@ namespace ModernKeePassLib.Utility
|
|||||||
|
|
||||||
return StrUtil.DataToDataUri(pb, "image/png");
|
return StrUtil.DataToDataUri(pb, "image/png");
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user