Repaired key file creation in lib

This commit is contained in:
BONNEVILLE Geoffroy
2017-11-15 17:56:31 +01:00
parent 7a632c8f80
commit 9313ac1abf
6 changed files with 42 additions and 20 deletions

View File

@@ -118,7 +118,7 @@ namespace ModernKeePassLib.Cryptography
for(i = 0; i < 16; ++i) pbTestData[i] = 0;
pbTestData[0] = 0x04;
#if ModernKeePassLib
#if ModernKeePassLib || KeePassUAP
AesEngine r = new AesEngine();
r.Init(true, new KeyParameter(pbTestKey));
if(r.GetBlockSize() != pbTestData.Length)
@@ -1032,7 +1032,7 @@ namespace ModernKeePassLib.Cryptography
private static void TestUrlUtil()
{
#if DEBUG
#if !ModernKeePassLib
#if !ModernKeePassLib && !KeePassUAP
Debug.Assert(Uri.UriSchemeHttp.Equals("http", StrUtil.CaseIgnoreCmp));
Debug.Assert(Uri.UriSchemeHttps.Equals("https", StrUtil.CaseIgnoreCmp));
#endif

View File

@@ -23,13 +23,13 @@ using System.IO;
using System.Security;
using System.Text;
using System.Xml;
#if ModernKeePassLib
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Storage;
#else
using System.Security.Cryptography;
#endif
@@ -68,6 +68,13 @@ namespace ModernKeePassLib.Keys
get { return m_pbKeyData; }
}
#if ModernKeePassLib
public KcpKeyFile(StorageFile strKeyFile)
{
Construct(IOConnectionInfo.FromFile(strKeyFile), false);
}
#endif
public KcpKeyFile(string strKeyFile)
{
Construct(IOConnectionInfo.FromPath(strKeyFile), false);
@@ -185,7 +192,11 @@ namespace ModernKeePassLib.Keys
/// the random key. May be <c>null</c> (in this case only the KeePass-internal
/// random number generator is used).</param>
/// <returns>Returns a <c>FileSaveResult</c> error code.</returns>
#if ModernKeePassLib
public static void Create(StorageFile strFilePath, byte[] pbAdditionalEntropy)
#else
public static void Create(string strFilePath, byte[] pbAdditionalEntropy)
#endif
{
byte[] pbKey32 = CryptoRandom.Instance.GetRandomBytes(32);
if(pbKey32 == null) throw new SecurityException();
@@ -293,18 +304,25 @@ namespace ModernKeePassLib.Keys
return pbKeyData;
}
#if ModernKeePassLib
private static void CreateXmlKeyFile(StorageFile strFile, byte[] pbKeyData)
#else
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
#endif
{
Debug.Assert(strFile != null);
if(strFile == null) throw new ArgumentNullException("strFile");
Debug.Assert(pbKeyData != null);
if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
#if ModernKeePassLib
IOConnectionInfo ioc = IOConnectionInfo.FromFile(strFile);
#else
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
#endif
Stream sOut = IOConnection.OpenWrite(ioc);
#if ModernKeePassLib
#if ModernKeePassLib || KeePassUAP
XmlWriterSettings xws = new XmlWriterSettings();
xws.Encoding = StrUtil.Utf8;
xws.Indent = false;

View File

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>ModernKeePassLib</id>
<version>2.37.6000</version>
<version>2.37.7000</version>
<title>ModernKeePassLib</title>
<authors>Geoffroy Bonneville</authors>
<owners>Geoffroy Bonneville</owners>
@@ -10,7 +10,7 @@
<projectUrl>https://github.com/wismna/ModernKeePass</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Portable KeePass Password Management Library that targets .Net Standard and WinRT. Allows reading, editing and writing to KeePass 2.x databases.</description>
<releaseNotes>TBD</releaseNotes>
<releaseNotes>Can now create key files</releaseNotes>
<copyright>Copyright © 2017 Geoffroy Bonneville</copyright>
<tags>KeePass KeePassLib Portable PCL NetStandard</tags>
<dependencies>