温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:Acom进出仓管理系统源码
当前文件路径:AcomStore/Components/PblogDes.cs

1////////////////////////////////////////////////////////////////////////// 2
// 创建人:Pconcool Liu-per@163.com 3
// 创建日期: 2007-09-16 4
// 描述: 5
// 6
// 修改日志: 7
// 8
// 版权:Http://www.Pconcool.com(c)2007-2010 9
////////////////////////////////////////////////////////////////////////// 10
11
using System; 12
using System.IO; 13
using System.Security.Cryptography; 14
using System.Text; 15
16
namespace AcomLb.Components 17
{ 18
19
public class PblogDes 20
{ 21
private string key; 22
23
public PblogDes() 24
{ 25
this.key = "PblogKey"; 26
} 27
28
public PblogDes(string key) 29
{ 30
this.key = key; 31
} 32
33
public string Decrypt(string s) 34
{ 35
return this.Decrypt(s, this.key); 36
} 37
38
private string Decrypt(string pToDecrypt, string sKey) 39
{ 40
DESCryptoServiceProvider provider = new DESCryptoServiceProvider(); 41
byte[] buffer = new byte[pToDecrypt.Length / 2]; 42
for (int i = 0; i < (pToDecrypt.Length / 2); i++) 43
{ 44
int num2 = Convert.ToInt32(pToDecrypt.Substring(i * 2, 2), 0x10); 45
buffer[i] = (byte)num2; 46
} 47
provider.Key = Encoding.ASCII.GetBytes(sKey); 48
provider.IV = Encoding.ASCII.GetBytes(sKey); 49
MemoryStream stream = new MemoryStream(); 50
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write); 51
stream2.Write(buffer, 0, buffer.Length); 52
stream2.FlushFinalBlock(); 53
new StringBuilder(); 54
return Encoding.Default.GetString(stream.ToArray()); 55
} 56
57
public string Encrypt(string s) 58
{ 59
return this.Encrypt(s, this.key); 60
} 61
62
private string Encrypt(string pToEncrypt, string sKey) 63
{ 64
DESCryptoServiceProvider provider = new DESCryptoServiceProvider(); 65
byte[] bytes = Encoding.Default.GetBytes(pToEncrypt); 66
provider.Key = Encoding.ASCII.GetBytes(sKey); 67
provider.IV = Encoding.ASCII.GetBytes(sKey); 68
MemoryStream stream = new MemoryStream(); 69
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write); 70
stream2.Write(bytes, 0, bytes.Length); 71
stream2.FlushFinalBlock(); 72
StringBuilder builder = new StringBuilder(); 73
foreach (byte num in stream.ToArray()) 74
{ 75
builder.AppendFormat("{0:X2}", num); 76
} 77
builder.ToString(); 78
return builder.ToString(); 79
} 80
} 81
} 82





}
}