using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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) { this._Key = key; this._IV = iv; } public string CryptorName { get { return "Rijndael"; } } public string Key { get { return _Key; } } public string IV { get { return _IV; } } public string Encrypt(string content) { return CryptoHelperService.RijndaelEncrypt(content, _Key, _IV); } public string Decrypt(string content) { return CryptoHelperService.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) { this._Key = publicKey; } public string CryptorName { get { return "RSA"; } } public string Key { get { return _Key; } } public string IV { get { return _IV; } } public string Encrypt(string content) { return CryptoHelperService.RSAEncrypt(content, _Key); } public string Decrypt(string content) { return CryptoHelperService.RSADecrypt(content, _Key); } }