mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Added a cryptography service to encrypt protected information (unused atm)
Corrected a bug when deleting recycle bin
This commit is contained in:
@@ -18,7 +18,7 @@ namespace ModernKeePass.Infrastructure
|
||||
public static IServiceCollection AddInfrastructureKeePass(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(typeof(IDatabaseProxy), typeof(KeePassDatabaseClient));
|
||||
services.AddTransient(typeof(ICryptographyClient), typeof(KeePassCryptographyClient));
|
||||
services.AddTransient(typeof(IDatabaseSettingsProxy), typeof(KeePassDatabaseSettingsProxy));
|
||||
services.AddTransient(typeof(ICredentialsProxy), typeof(KeePassCredentialsClient));
|
||||
return services;
|
||||
}
|
||||
@@ -29,6 +29,7 @@ namespace ModernKeePass.Infrastructure
|
||||
services.AddTransient(typeof(ISettingsProxy), typeof(UwpSettingsClient));
|
||||
services.AddTransient(typeof(IRecentProxy), typeof(UwpRecentFilesClient));
|
||||
services.AddTransient(typeof(IResourceProxy), typeof(UwpResourceClient));
|
||||
services.AddTransient(typeof(ICryptographyClient), typeof(UwpCryptographyClient));
|
||||
services.AddTransient(typeof(INotificationService), typeof(ToastNotificationService));
|
||||
return services;
|
||||
}
|
||||
|
@@ -82,12 +82,13 @@
|
||||
<Compile Include="KeePass\EntryFieldMapper.cs" />
|
||||
<Compile Include="KeePass\MappingProfiles.cs" />
|
||||
<Compile Include="KeePass\IconMapper.cs" />
|
||||
<Compile Include="KeePass\KeePassCryptographyClient.cs" />
|
||||
<Compile Include="KeePass\KeePassDatabaseSettingsProxy.cs" />
|
||||
<Compile Include="KeePass\KeePassDatabaseClient.cs" />
|
||||
<Compile Include="KeePass\KeePassCredentialsClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UWP\StorageFileClient.cs" />
|
||||
<Compile Include="UWP\ToastNotificationService.cs" />
|
||||
<Compile Include="UWP\UwpCryptographyClient.cs" />
|
||||
<Compile Include="UWP\UwpRecentFilesClient.cs" />
|
||||
<Compile Include="UWP\UwpResourceClient.cs" />
|
||||
<Compile Include="UWP\UwpSettingsClient.cs" />
|
||||
|
@@ -9,7 +9,7 @@ using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.KeePass
|
||||
{
|
||||
public class KeePassCryptographyClient: ICryptographyClient
|
||||
public class KeePassDatabaseSettingsProxy: IDatabaseSettingsProxy
|
||||
{
|
||||
public IEnumerable<BaseEntity> Ciphers
|
||||
{
|
47
ModernKeePass.Infrastructure/UWP/UwpCryptographyClient.cs
Normal file
47
ModernKeePass.Infrastructure/UWP/UwpCryptographyClient.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Security.Cryptography;
|
||||
using Windows.Security.Cryptography.DataProtection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public class UwpCryptographyClient: ICryptographyClient
|
||||
{
|
||||
public async Task<string> Protect(string value)
|
||||
{
|
||||
// Create a DataProtectionProvider object for the specified descriptor.
|
||||
var provider = new DataProtectionProvider();
|
||||
|
||||
// Encode the plaintext input message to a buffer.
|
||||
var buffMsg = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8);
|
||||
|
||||
// Encrypt the message.
|
||||
var buffProtected = await provider.ProtectAsync(buffMsg);
|
||||
|
||||
// Encode buffer to Base64
|
||||
var stringProtected = CryptographicBuffer.EncodeToBase64String(buffProtected);
|
||||
|
||||
// Return the encrypted string.
|
||||
return stringProtected;
|
||||
}
|
||||
|
||||
public async Task<string> UnProtect(string value)
|
||||
{
|
||||
// Create a DataProtectionProvider object.
|
||||
var provider = new DataProtectionProvider();
|
||||
|
||||
// Decode from Base64 string
|
||||
var buffProtected = CryptographicBuffer.DecodeFromBase64String(value);
|
||||
|
||||
// Decrypt the protected message specified on input.
|
||||
var buffUnprotected = await provider.UnprotectAsync(buffProtected);
|
||||
|
||||
// Convert the unprotected message from an IBuffer object to a string.
|
||||
var strClearText = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, buffUnprotected);
|
||||
|
||||
// Return the plaintext string.
|
||||
return strClearText;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user