mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added backward compatibility support to encrypted string value provider
This commit is contained in:
parent
4371884843
commit
dfe387a113
1 changed files with 15 additions and 10 deletions
|
@ -30,6 +30,8 @@ namespace ShareX.HelpersLib
|
|||
{
|
||||
public class DPAPIEncryptedStringValueProvider : IValueProvider
|
||||
{
|
||||
private const string encryptedTag = "$DPAPIEncrypted$";
|
||||
|
||||
private PropertyInfo targetProperty;
|
||||
|
||||
public DPAPIEncryptedStringValueProvider(PropertyInfo targetProperty)
|
||||
|
@ -40,13 +42,12 @@ public DPAPIEncryptedStringValueProvider(PropertyInfo targetProperty)
|
|||
public object GetValue(object target)
|
||||
{
|
||||
string value = (string)targetProperty.GetValue(target);
|
||||
string encryptedValue = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
try
|
||||
{
|
||||
encryptedValue = DPAPI.Encrypt(value);
|
||||
value = encryptedTag + DPAPI.Encrypt(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -54,22 +55,26 @@ public object GetValue(object target)
|
|||
|
||||
}
|
||||
|
||||
return encryptedValue;
|
||||
return value;
|
||||
}
|
||||
|
||||
public void SetValue(object target, object value)
|
||||
{
|
||||
string decryptedValue = null;
|
||||
string text = (string)value;
|
||||
|
||||
if (!string.IsNullOrEmpty(text) && text.StartsWith(encryptedTag))
|
||||
{
|
||||
try
|
||||
{
|
||||
decryptedValue = DPAPI.Decrypt((string)value);
|
||||
string encryptedString = text.Substring(encryptedTag.Length);
|
||||
text = DPAPI.Decrypt(encryptedString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
targetProperty.SetValue(target, decryptedValue);
|
||||
targetProperty.SetValue(target, text);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue