mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Added the possibility to automatically encrypt/decrypt a configuration value by setting "Encrypted" in the ini to true. Also added a small OAuth example in the ImgurUtils, for later usage.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2014 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
b2ea24fd9a
commit
79cbe548b0
4 changed files with 41 additions and 2 deletions
|
@ -261,5 +261,22 @@ namespace GreenshotImgurPlugin {
|
||||||
|
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ImgurOAuthExample() {
|
||||||
|
OAuthHelper oAuth = new OAuthHelper();
|
||||||
|
oAuth.CallbackUrl = "http://getgreenshot.org";
|
||||||
|
oAuth.AccessTokenUrl = "https://api.imgur.com/oauth/access_token";
|
||||||
|
oAuth.AuthorizeUrl = "https://api.imgur.com/oauth/authorize";
|
||||||
|
oAuth.RequestTokenUrl = "https://api.imgur.com/oauth/request_token";
|
||||||
|
oAuth.ConsumerKey = "907d4455b8c38144d68c4f72190af4c40504a0ac7";
|
||||||
|
oAuth.ConsumerSecret = "d33902ef409fea163ab755454c15b3d0";
|
||||||
|
oAuth.UserAgent = "Greenshot";
|
||||||
|
oAuth.getRequestToken();
|
||||||
|
if (string.IsNullOrEmpty(oAuth.authorizeToken("Imgur authorization"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string accessToken = oAuth.getAccessToken();
|
||||||
|
MessageBox.Show(oAuth.oAuthWebRequest(OAuth.Method.GET, "http://api.imgur.com/2/account", null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="ClearText">the string to call upon</param>
|
/// <param name="ClearText">the string to call upon</param>
|
||||||
/// <returns>an encryped string in base64 form</returns>
|
/// <returns>an encryped string in base64 form</returns>
|
||||||
public static string Encrypt(this string ClearText) {
|
public static string Encrypt(this string ClearText) {
|
||||||
string returnValue = null;
|
string returnValue = ClearText;
|
||||||
try {
|
try {
|
||||||
byte[] clearTextBytes = Encoding.ASCII.GetBytes(ClearText);
|
byte[] clearTextBytes = Encoding.ASCII.GetBytes(ClearText);
|
||||||
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
|
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
|
||||||
|
@ -63,7 +63,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="EncryptedText">a base64 encoded rijndael encrypted string</param>
|
/// <param name="EncryptedText">a base64 encoded rijndael encrypted string</param>
|
||||||
/// <returns>Decrypeted text</returns>
|
/// <returns>Decrypeted text</returns>
|
||||||
public static string Decrypt(this string EncryptedText) {
|
public static string Decrypt(this string EncryptedText) {
|
||||||
string returnValue = null;
|
string returnValue = EncryptedText;
|
||||||
try {
|
try {
|
||||||
byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
|
byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
|
||||||
using (MemoryStream ms = new MemoryStream()) {
|
using (MemoryStream ms = new MemoryStream()) {
|
||||||
|
|
|
@ -50,6 +50,8 @@ namespace Greenshot.IniFile {
|
||||||
public string Separator = ",";
|
public string Separator = ",";
|
||||||
public string DefaultValue;
|
public string DefaultValue;
|
||||||
public string LanguageKey;
|
public string LanguageKey;
|
||||||
|
// If Encrypted is set to true, the value will be decrypted on load and encrypted on save
|
||||||
|
public bool Encrypted = false;
|
||||||
public bool FixedValue = false;
|
public bool FixedValue = false;
|
||||||
public bool ExcludeIfNull=false;
|
public bool ExcludeIfNull=false;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
|
||||||
namespace Greenshot.IniFile {
|
namespace Greenshot.IniFile {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -141,6 +142,12 @@ namespace Greenshot.IniFile {
|
||||||
IniValue iniValue = Values[fieldName];
|
IniValue iniValue = Values[fieldName];
|
||||||
try {
|
try {
|
||||||
iniValue.SetValueFromProperties(properties);
|
iniValue.SetValueFromProperties(properties);
|
||||||
|
if (iniValue.Attributes.Encrypted) {
|
||||||
|
string stringValue = iniValue.Value as string;
|
||||||
|
if (stringValue != null && stringValue.Length > 2) {
|
||||||
|
iniValue.Value = stringValue.Decrypt();
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.Error(ex);
|
LOG.Error(ex);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +173,20 @@ namespace Greenshot.IniFile {
|
||||||
writer.WriteLine("[{0}]", IniSectionAttribute.Name);
|
writer.WriteLine("[{0}]", IniSectionAttribute.Name);
|
||||||
|
|
||||||
foreach (IniValue value in Values.Values) {
|
foreach (IniValue value in Values.Values) {
|
||||||
|
if (value.Attributes.Encrypted) {
|
||||||
|
string stringValue = value.Value as string;
|
||||||
|
if (stringValue != null && stringValue.Length > 2) {
|
||||||
|
value.Value = stringValue.Encrypt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Write the value
|
||||||
value.Write(writer, onlyProperties);
|
value.Write(writer, onlyProperties);
|
||||||
|
if (value.Attributes.Encrypted) {
|
||||||
|
string stringValue = value.Value as string;
|
||||||
|
if (stringValue != null && stringValue.Length > 2) {
|
||||||
|
value.Value = stringValue.Decrypt();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
AfterSave();
|
AfterSave();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue