using CSFrameworkV5.Core.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSFrameworkV5.Core.Common
{
///
/// 平台支持的对称加密类型
///
public class KeyProvider
{
///
/// 预设密钥,初始化系统时设置
///
public static string DefaultKey { get; set; }
///
/// 预设偏移量,初始化系统时设置
///
public static string DefaultIV { get; set; }
///
/// 预设对称加密工具
///
public static IKeyProvider Default { get; set; }
}
///
/// 对称加密密钥接口
///
public interface IKeyProvider
{
///
/// 密钥名称
///
string CryptorName { get; }
string Key { get; }
string IV { get; }
string Encrypt(string content);
string Decrypt(string content);
}
public class KeyProviderRijndael : IKeyProvider
{
private string _Key = "";
private string _IV = "";
public KeyProviderRijndael(string key, string iv)
{
_Key = key;
_IV = iv;
}
public string CryptorName => "Rijndael";
public string Key => _Key;
public string IV => _IV;
public string Encrypt(string content)
{
return CryptoHelper.RijndaelEncrypt(content, _Key, _IV);
}
public string Decrypt(string content)
{
return CryptoHelper.RijndaelDecrypt(content, _Key, _IV);
}
}
//public class KeyProviderTripleDES : IKeyProvider
//{
// private string _Key = "";
// private string _IV = "";
// public KeyProviderTripleDES(string key, string iv)
// {
// this._Key = key;
// this._IV = iv;
// }
// public string CryptorName { get { return "TripleDES"; } }
// public string Key { get { return _Key; } }
// public string IV { get { return _IV; } }
// public string Encrypt(string content)
// {
// return CryptoHelper.TripleDESEncrypt(content, _Key, _IV);
// }
// public string Decrypt(string content)
// {
// return CryptoHelper.TripleDESDecrypt(content, _Key, _IV);
// }
//}
public class KeyProviderRSA : IKeyProvider
{
private string _Key = "";
private string _IV = "";
public KeyProviderRSA(string publicKey)
{
_Key = publicKey;
}
public string CryptorName => "RSA";
public string Key => _Key;
public string IV => _IV;
public string Encrypt(string content)
{
return CryptoHelper.RSAEncrypt(content, _Key);
}
public string Decrypt(string content)
{
return CryptoHelper.RSADecrypt(content, _Key);
}
}
}