mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 15:40:20 -04:00
Removed dependencies to UWP SDK
Added ImageSharp for image processing
This commit is contained in:
@@ -27,9 +27,6 @@ using System.Xml;
|
||||
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,9 +65,9 @@ namespace ModernKeePassLib.Keys
|
||||
get { return m_pbKeyData; }
|
||||
}
|
||||
#if ModernKeePassLib
|
||||
public KcpKeyFile(StorageFile keyFile)
|
||||
public KcpKeyFile(byte[] keyFile)
|
||||
{
|
||||
Construct(IOConnectionInfo.FromStorageFile(keyFile), false);
|
||||
Construct(IOConnectionInfo.FromByteArray(keyFile), false);
|
||||
}
|
||||
#else
|
||||
public KcpKeyFile(string strKeyFile)
|
||||
@@ -192,7 +189,7 @@ namespace ModernKeePassLib.Keys
|
||||
/// random number generator is used).</param>
|
||||
/// <returns>Returns a <c>FileSaveResult</c> error code.</returns>
|
||||
#if ModernKeePassLib
|
||||
public static void Create(StorageFile file, byte[] pbAdditionalEntropy)
|
||||
public static byte[] Create(byte[] pbAdditionalEntropy)
|
||||
#else
|
||||
public static void Create(string strFilePath, byte[] pbAdditionalEntropy)
|
||||
#endif
|
||||
@@ -215,7 +212,7 @@ namespace ModernKeePassLib.Keys
|
||||
}
|
||||
|
||||
#if ModernKeePassLib
|
||||
CreateXmlKeyFile(file, pbFinalKey32);
|
||||
return CreateXmlKeyFile(pbFinalKey32);
|
||||
#else
|
||||
CreateXmlKeyFile(strFilePath, pbFinalKey32);
|
||||
#endif
|
||||
@@ -281,10 +278,8 @@ namespace ModernKeePassLib.Keys
|
||||
}
|
||||
|
||||
#if ModernKeePassLib
|
||||
private static void CreateXmlKeyFile(StorageFile file, byte[] pbKeyData)
|
||||
private static byte[] CreateXmlKeyFile(byte[] pbKeyData)
|
||||
{
|
||||
Debug.Assert(file != null);
|
||||
if (file == null) throw new ArgumentNullException(nameof(file));
|
||||
#else
|
||||
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
|
||||
{
|
||||
@@ -295,7 +290,8 @@ namespace ModernKeePassLib.Keys
|
||||
if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
|
||||
|
||||
#if ModernKeePassLib
|
||||
var ioc = IOConnectionInfo.FromStorageFile(file);
|
||||
var fileContents = new byte[0];
|
||||
var ioc = IOConnectionInfo.FromByteArray(fileContents);
|
||||
#else
|
||||
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
|
||||
#endif
|
||||
@@ -323,7 +319,10 @@ namespace ModernKeePassLib.Keys
|
||||
xw.WriteEndElement(); // </KeyFile>
|
||||
xw.WriteEndDocument();
|
||||
}
|
||||
#if ModernKeePassLib
|
||||
return ((MemoryStream) s).ToArray();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,12 +23,10 @@ using System.IO;
|
||||
using System.Security;
|
||||
|
||||
#if ModernKeePassLib
|
||||
using Windows.Storage;
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Native;
|
||||
using ModernKeePassLib.Resources;
|
||||
using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Utility;
|
||||
@@ -87,8 +85,8 @@ namespace ModernKeePassLib.Keys
|
||||
|
||||
private static string GetUserKeyFilePath(bool bCreate)
|
||||
{
|
||||
#if ModernKeePassLib
|
||||
string strUserDir = Windows.Storage.ApplicationData.Current.RoamingFolder.Path;
|
||||
#if KeePassUAP
|
||||
string strUserDir = EnvironmentExt.AppDataRoamingFolderPath;
|
||||
#else
|
||||
string strUserDir = Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData);
|
||||
@@ -97,11 +95,8 @@ namespace ModernKeePassLib.Keys
|
||||
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
|
||||
strUserDir += PwDefs.ShortProductName;
|
||||
|
||||
#if !ModernKeePassLib
|
||||
|
||||
if(bCreate && !Directory.Exists(strUserDir))
|
||||
Directory.CreateDirectory(strUserDir);
|
||||
#endif
|
||||
|
||||
strUserDir = UrlUtil.EnsureTerminatingSeparator(strUserDir, false);
|
||||
return (strUserDir + UserKeyFileName);
|
||||
@@ -115,15 +110,7 @@ namespace ModernKeePassLib.Keys
|
||||
try
|
||||
{
|
||||
string strFilePath = GetUserKeyFilePath(false);
|
||||
|
||||
#if ModernKeePassLib
|
||||
var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForReadAsync().GetAwaiter().GetResult();
|
||||
var pbProtectedKey = new byte[(int)fileStream.Length];
|
||||
fileStream.Read(pbProtectedKey, 0, (int)fileStream.Length);
|
||||
fileStream.Dispose();
|
||||
#else
|
||||
byte[] pbProtectedKey = File.ReadAllBytes(strFilePath);
|
||||
#endif
|
||||
|
||||
pbKey = CryptoUtil.UnprotectData(pbProtectedKey, m_pbEntropy,
|
||||
DataProtectionScope.CurrentUser);
|
||||
@@ -148,13 +135,8 @@ namespace ModernKeePassLib.Keys
|
||||
byte[] pbRandomKey = CryptoRandom.Instance.GetRandomBytes(64);
|
||||
byte[] pbProtectedKey = CryptoUtil.ProtectData(pbRandomKey,
|
||||
m_pbEntropy, DataProtectionScope.CurrentUser);
|
||||
#if ModernKeePassLib
|
||||
var fileStream = StorageFile.GetFileFromPathAsync(strFilePath).GetAwaiter().GetResult().OpenStreamForWriteAsync().GetAwaiter().GetResult();
|
||||
fileStream.Write(pbProtectedKey, 0, (int)fileStream.Length);
|
||||
fileStream.Dispose();
|
||||
#else
|
||||
|
||||
File.WriteAllBytes(strFilePath, pbProtectedKey);
|
||||
#endif
|
||||
|
||||
byte[] pbKey = LoadUserKey(true);
|
||||
Debug.Assert(MemUtil.ArraysEqual(pbKey, pbRandomKey));
|
||||
|
Reference in New Issue
Block a user