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:
RKrom 2012-09-09 13:53:53 +00:00
parent b2ea24fd9a
commit 79cbe548b0
4 changed files with 41 additions and 2 deletions

View file

@ -261,5 +261,22 @@ namespace GreenshotImgurPlugin {
} 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));
}
}
}

View file

@ -36,7 +36,7 @@ namespace GreenshotPlugin.Core {
/// <param name="ClearText">the string to call upon</param>
/// <returns>an encryped string in base64 form</returns>
public static string Encrypt(this string ClearText) {
string returnValue = null;
string returnValue = ClearText;
try {
byte[] clearTextBytes = Encoding.ASCII.GetBytes(ClearText);
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
@ -63,7 +63,7 @@ namespace GreenshotPlugin.Core {
/// <param name="EncryptedText">a base64 encoded rijndael encrypted string</param>
/// <returns>Decrypeted text</returns>
public static string Decrypt(this string EncryptedText) {
string returnValue = null;
string returnValue = EncryptedText;
try {
byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
using (MemoryStream ms = new MemoryStream()) {

View file

@ -50,6 +50,8 @@ namespace Greenshot.IniFile {
public string Separator = ",";
public string DefaultValue;
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 ExcludeIfNull=false;

View file

@ -22,6 +22,7 @@ using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using GreenshotPlugin.Core;
namespace Greenshot.IniFile {
/// <summary>
@ -141,6 +142,12 @@ namespace Greenshot.IniFile {
IniValue iniValue = Values[fieldName];
try {
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) {
LOG.Error(ex);
}
@ -166,7 +173,20 @@ namespace Greenshot.IniFile {
writer.WriteLine("[{0}]", IniSectionAttribute.Name);
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);
if (value.Attributes.Encrypted) {
string stringValue = value.Value as string;
if (stringValue != null && stringValue.Length > 2) {
value.Value = stringValue.Decrypt();
}
}
}
} finally {
AfterSave();