StringEncryptionExtensions.cs
3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using NCC.Dependency;
namespace NCC.DataEncryption.Extensions
{
/// <summary>
/// DataEncryption 字符串加密拓展
/// </summary>
[SuppressSniffer]
public static class StringEncryptionExtensions
{
/// <summary>
/// 字符串的 MD5
/// </summary>
/// <param name="text"></param>
/// <param name="uppercase">是否输出大写加密,默认 false</param>
/// <returns>string</returns>
public static string ToMD5Encrypt(this string text, bool uppercase = false)
{
return MD5Encryption.Encrypt(text, uppercase);
}
/// <summary>
/// 字符串的 MD5
/// </summary>
/// <param name="text"></param>
/// <param name="hash"></param>
/// <param name="uppercase">是否输出大写加密,默认 false</param>
/// <returns>string</returns>
public static bool ToMD5Compare(this string text, string hash, bool uppercase = false)
{
return MD5Encryption.Compare(text, hash, uppercase);
}
/// <summary>
/// 字符串 AES 加密
/// </summary>
/// <param name="text">需要加密的字符串</param>
/// <param name="skey"></param>
/// <returns>string</returns>
public static string ToAESEncrypt(this string text, string skey)
{
return AESEncryption.Encrypt(text, skey);
}
/// <summary>
/// 字符串 AES 解密
/// </summary>
/// <param name="text"></param>
/// <param name="skey"></param>
/// <returns>string</returns>
public static string ToAESDecrypt(this string text, string skey)
{
return AESEncryption.Decrypt(text, skey);
}
/// <summary>
/// 字符串 DESC 加密
/// </summary>
/// <param name="text">需要加密的字符串</param>
/// <param name="skey">密钥</param>
/// <param name="uppercase">是否输出大写加密,默认 false</param>
/// <returns>string</returns>
public static string ToDESCEncrypt(this string text, string skey, bool uppercase = false)
{
return DESCEncryption.Encrypt(text, skey, uppercase);
}
/// <summary>
/// 字符串 DESC 解密
/// </summary>
/// <param name="text"></param>
/// <param name="skey">密钥</param>
/// <param name="uppercase">是否输出大写加密,默认 false</param>
/// <returns>string</returns>
public static string ToDESCDecrypt(this string text, string skey, bool uppercase = false)
{
return DESCEncryption.Decrypt(text, skey, uppercase);
}
/// <summary>
/// 字符串 RSA 加密
/// </summary>
/// <param name="text">需要加密的文本</param>
/// <param name="publicKey">公钥</param>
/// <returns></returns>
public static string ToRSAEncrpyt(this string text, string publicKey)
{
return RSAEncryption.Encrypt(text, publicKey);
}
/// <summary>
/// 字符串 RSA 解密
/// </summary>
/// <param name="text">需要解密的文本</param>
/// <param name="privateKey">私钥</param>
/// <returns></returns>
public static string ToRSADecrypt(this string text, string privateKey)
{
return RSAEncryption.Decrypt(text, privateKey);
}
}
}