|
|
|
@ -14,7 +14,7 @@ namespace isn
|
|
|
|
/// Protected API Key
|
|
|
|
/// Protected API Key
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <value></value>
|
|
|
|
/// <value></value>
|
|
|
|
public string ProtectedApiKey { get; set; }
|
|
|
|
public string ApiKey { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Key alias
|
|
|
|
/// Key alias
|
|
|
|
@ -26,16 +26,14 @@ namespace isn
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetClearApiKey(RSA rsa)
|
|
|
|
public string GetClearApiKey()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var decrypted = rsa.Decrypt(System.Convert.FromBase64String(ProtectedApiKey), RSAEncryptionPadding.Pkcs1);
|
|
|
|
return ApiKey;
|
|
|
|
return Encoding.Default.GetString(decrypted);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetApiKey(RSA rsa, string key)
|
|
|
|
public void SetApiKey(string key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var ciphered =rsa.Encrypt(Encoding.Default.GetBytes(key), RSAEncryptionPadding.Pkcs1);
|
|
|
|
ApiKey = key;
|
|
|
|
ProtectedApiKey = System.Convert.ToBase64String(ciphered);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -48,14 +46,11 @@ namespace isn
|
|
|
|
|
|
|
|
|
|
|
|
public static Settings Create()
|
|
|
|
public static Settings Create()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var rsaParams = CreateCipheringParameters();
|
|
|
|
|
|
|
|
return new Settings {
|
|
|
|
return new Settings {
|
|
|
|
RSAParameters = rsaParams,
|
|
|
|
|
|
|
|
Sources = new Dictionary<string, SourceSettings>()
|
|
|
|
Sources = new Dictionary<string, SourceSettings>()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RSAParameters RSAParameters { get; set; }
|
|
|
|
|
|
|
|
public Dictionary<string, SourceSettings> Sources { get; set; }
|
|
|
|
public Dictionary<string, SourceSettings> Sources { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private string defSourceKey;
|
|
|
|
private string defSourceKey;
|
|
|
|
@ -77,16 +72,19 @@ namespace isn
|
|
|
|
[JsonIgnore, NotMapped]
|
|
|
|
[JsonIgnore, NotMapped]
|
|
|
|
public string CurrentSourceKey {get; set;}
|
|
|
|
public string CurrentSourceKey {get; set;}
|
|
|
|
|
|
|
|
|
|
|
|
private static RSAParameters CreateCipheringParameters()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var provider = new RSACryptoServiceProvider(2048);
|
|
|
|
|
|
|
|
return provider.ExportParameters(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[JsonIgnore, NotMapped]
|
|
|
|
[JsonIgnore, NotMapped]
|
|
|
|
public SourceSettings CurrentSource
|
|
|
|
public SourceSettings CurrentSource
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => this.Sources[CurrentSourceKey];
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (CurrentSourceKey==null) return null;
|
|
|
|
|
|
|
|
if (!Sources.ContainsKey(CurrentSourceKey))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Sources.Add(CurrentSourceKey, new SourceSettings());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Sources[CurrentSourceKey];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|