关于C/S快速开发框架采用的文本加密解密策略|C/S框架网
关于C/S快速开发框架采用的文本加密解密策略|C/S框架网
KeyProvider类作为贯穿整个系统的全局类,定义全局变量IKeyProvider Default,在初始化系统时实例化Default属性:
5. 使用方法:
1. 加密解密程序通用接口 - IKeyProvider:
C# Code:
//加密解密程序通用接口
public interface IKeyProvider
{
string CryptorName { get; }
string IV { get; }
string Key { get; }
string Decrypt(string content);
string Encrypt(string content);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
//加密解密程序通用接口
public interface IKeyProvider
{
string CryptorName { get; }
string IV { get; }
string Key { get; }
string Decrypt(string content);
string Encrypt(string content);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
2. 加密解密策略之一 Rijndael算法(对称加解密):
C# Code:
public class KeyProviderRijndael : IKeyProvider
{
public KeyProviderRijndael(string key, string iv);
public string CryptorName { get; }
public string IV { get; }
public string Key { get; }
public string Decrypt(string content);
public string Encrypt(string content);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
public class KeyProviderRijndael : IKeyProvider
{
public KeyProviderRijndael(string key, string iv);
public string CryptorName { get; }
public string IV { get; }
public string Key { get; }
public string Decrypt(string content);
public string Encrypt(string content);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
3. 加密解密策略之二 DES算法(对称加解密):
C# Code:
public class KeyProviderDES : IKeyProvider
{
public KeyProviderDES(string key, string iv);
public string CryptorName { get; }
public string IV { get; }
public string Key { get; }
public string Decrypt(string content);
public string Encrypt(string content);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
public class KeyProviderDES : IKeyProvider
{
public KeyProviderDES(string key, string iv);
public string CryptorName { get; }
public string IV { get; }
public string Key { get; }
public string Decrypt(string content);
public string Encrypt(string content);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
4. 加解密全局类(工具类) - KeyProvider:
C# Code:
public class KeyProvider
{
public KeyProvider();
public static IKeyProvider Default { get; set; }
public static string DefaultIV { get; set; }
public static string DefaultKey { get; set; }
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
public class KeyProvider
{
public KeyProvider();
public static IKeyProvider Default { get; set; }
public static string DefaultIV { get; set; }
public static string DefaultKey { get; set; }
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
KeyProvider.Default = new KeyProviderRijndael("1SaFz$^p", "3aW%^aFd");//初始化对称加密预设秘钥
KeyProvider.Default = new KeyProviderRijndael("1SaFz$^p", "3aW%^aFd");//初始化对称加密预设秘钥
string key = KeyProvider.Default.Decrypt("3H0hVJsk1255KgahWKTyGA==");//测试解密
5. 使用方法:
C# Code:
KeyProvider.Default.Encrypt("test");//测试加密
KeyProvider.Default.Decrypt("3H0hVJsk1255KgahWKTyGA==");//测试解密
//来源:C/S框架网(www.csframework.com) QQ:23404761
KeyProvider.Default.Encrypt("test");//测试加密
KeyProvider.Default.Decrypt("3H0hVJsk1255KgahWKTyGA==");//测试解密
//来源:C/S框架网(www.csframework.com) QQ:23404761
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网