|
|
|
[.Net C#] Class สำหรับการเข้ารหัส Password และข้อมูลที่ต้อง และการถอดรหัส |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Security.Cryptography;
using System.Text;
namespace Encrypt
{
public static class Encryption
{
private const string cryptoKey = "czsqO+DxnA1EcyurkKdllA==";
private static readonly byte[] IV =
new byte[8] { 240, 3, 45, 29, 0, 76, 173, 59 };
public static string Encrypt(string s)
{
if (s == null || s.Length == 0) return string.Empty;
string result = string.Empty;
try
{
byte[] buffer = Encoding.Default.GetBytes(s);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(ASCIIEncoding.UTF32.GetBytes(cryptoKey));
des.IV = IV;
result = Convert.ToBase64String(
des.CreateEncryptor().TransformFinalBlock(
buffer, 0, buffer.Length));
}
catch(Exception ex)
{
throw ex;
}
return result;
}
public static string Decrypt(string s)
{
if (s == null || s.Length == 0) return string.Empty;
string result = string.Empty;
try
{
byte[] buffer = Convert.FromBase64String(s);
TripleDESCryptoServiceProvider des =new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 =new MD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(ASCIIEncoding.UTF32.GetBytes(cryptoKey));
des.IV = IV;
result = Encoding.Default.GetString(
des.CreateDecryptor().TransformFinalBlock(
buffer, 0, buffer.Length));
}
catch(Exception ex)
{
throw ex;
}
return result;
}
}
}
Tag : .NET, Class Library, C#, Windows
|
|
|
|
|
|
Date :
2013-07-15 15:41:38 |
By :
anonymouse |
View :
3826 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-07-15 16:16:01 |
By :
fonfire |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จัดไปครับ
|
|
|
|
|
Date :
2013-07-15 16:17:34 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|