Username:用户名,采用AZDG加密方式进行加密
Passwrod:密码,采用AZDG加密方式进行加密
密钥为:chinagdn
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 |
/// <summary> /// 短信发送AZDG加密算法 /// </summary> /// <param name="txt">加密字符串</param> /// <param name="key">私有密钥</param> /// <returns></returns> public
static string passport_encrypt( string
txt, string
key) { // 使用随机数产生 0~32000 的值并 MD5() Random rnd = new
Random(100); int
int_encrypt_key = rnd.Next(0, 32000); string
encrypt_key = int_encrypt_key.ToString(); int
ctr = 0; string
tmp = "" ; byte [] encodebyte = new
byte [txt.Length]; for
( int
i = 0; i < txt.Length; i++) { ctr = ctr == encrypt_key.Length ? 0 : ctr; char
prefix = encrypt_key[ctr]; char
left = txt[i]; char
right = encrypt_key[ctr++]; encodebyte[i] = ( byte )(left ^ right); char [] block = new
char [2]; block[0] = prefix; block[1] = Convert.ToChar(encodebyte[i]); tmp += new
string (block); } //用base64编码 string
complicatedstring = passport_key(tmp, key); //先和key加一次密? byte [] inputbytes = System.Text.Encoding.Default.GetBytes(complicatedstring); string
string_64 = Convert.ToBase64String(inputbytes, 0, inputbytes.Length); //再和随机key加密 return
string_64; } /// <summary> /// Passport 解密函数 /// </summary> /// <param name="txt">加密后的字串</param> /// <param name="key">私有密匙(用于解密和加密)</param> /// <returns>字串经过私有密匙解密后的结果</returns> public
static string passport_decrypt( string
txt, string
key) { byte [] array_64 = Convert.FromBase64String(txt); string
txt_64 = System.Text.Encoding.Default.GetString(array_64); txt = passport_key(txt_64, key); string
temp = "" ; byte [] encodebyte = new
byte [txt.Length]; for
( int
i = 0; i < txt.Length; i++) { char
left = txt[i]; char
right = txt[++i]; encodebyte[i] = ( byte )(left ^ right); } temp = System.Text.Encoding.Default.GetString(encodebyte); return
temp; } /// <summary> /// Passport 密匙处理函数 /// </summary> /// <param name="txt">待加密或待解密的字串</param> /// <param name="encrypt_key">私有密匙(用于解密和加密)</param> /// <returns>处理后的密匙</returns> public
static string passport_key( string
txt, string
encrypt_key) { //先md5编码 encrypt_key = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(encrypt_key, "MD5" ).ToString().ToLower(); int
ctr = 0; string
tmp = "" ; byte [] encodebyte = new
byte [txt.Length]; for
( int
i = 0; i < txt.Length; i++) { ctr = ctr == encrypt_key.Length ? 0 : ctr; char
left = txt[i]; char
right = encrypt_key[ctr++]; encodebyte[i] = ( byte )(left ^ right); } tmp = System.Text.Encoding.Default.GetString(encodebyte); return
tmp; } |
1
2 |
//插入下发短信 string
message = smsclient.InsertDownSms(passport_encrypt(username, "chinagdn" ), passport_encrypt(password, "chinagdn" ), "" , sb.ToString()); |
原文:http://www.cnblogs.com/Warmsunshine/p/3749879.html