620 lines
23 KiB
C#
620 lines
23 KiB
C#
|
|
using System;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Security.Cryptography;
|
|||
|
|
|
|||
|
|
namespace WinformGeneralDeveloperFrame.Commons
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// DES<45>ԳƼӽ<C6BC><D3BD>ܡ<EFBFBD>AES RijndaelManaged<65>ӽ<EFBFBD><D3BD>ܡ<EFBFBD>Base64<36><34><EFBFBD>ܽ<EFBFBD><DCBD>ܡ<EFBFBD>MD5<44><35><EFBFBD>ܵȲ<DCB5><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public sealed class EncodeHelper
|
|||
|
|
{
|
|||
|
|
#region DES<45>ԳƼ<D4B3><C6BC>ܽ<EFBFBD><DCBD><EFBFBD>
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ע<><D7A2>DEFAULT_ENCRYPT_KEY<45>ij<EFBFBD><C4B3><EFBFBD>Ϊ8λ(<28><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD><DFBC><EFBFBD>key<65><79><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>IV<49>ij<EFBFBD><C4B3>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
|
/// </summary>
|
|||
|
|
public const string DEFAULT_ENCRYPT_KEY = "12345678";
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʹ<><CAB9>Ĭ<EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strText"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string DesEncrypt(string strText)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return DesEncrypt(strText, DEFAULT_ENCRYPT_KEY);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʹ<><CAB9>Ĭ<EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strText"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string DesDecrypt(string strText)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return DesDecrypt(strText, DEFAULT_ENCRYPT_KEY);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>,ע<><D7A2>strEncrKey<65>ij<EFBFBD><C4B3><EFBFBD>Ϊ8λ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strText"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="strEncrKey"><3E><><EFBFBD>ܼ<EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string DesEncrypt(string strText, string strEncrKey)
|
|||
|
|
{
|
|||
|
|
byte[] byKey = null;
|
|||
|
|
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
|||
|
|
|
|||
|
|
byKey = Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8));
|
|||
|
|
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|||
|
|
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
|
|||
|
|
MemoryStream ms = new MemoryStream();
|
|||
|
|
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
|
|||
|
|
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
|||
|
|
cs.FlushFinalBlock();
|
|||
|
|
return Convert.ToBase64String(ms.ToArray());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>,ע<><D7A2>strEncrKey<65>ij<EFBFBD><C4B3><EFBFBD>Ϊ8λ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strText"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="sDecrKey"><3E><><EFBFBD>ܼ<EFBFBD></param>
|
|||
|
|
/// <returns><3E><><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|||
|
|
public static string DesDecrypt(string strText, string sDecrKey)
|
|||
|
|
{
|
|||
|
|
byte[] byKey = null;
|
|||
|
|
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
|||
|
|
byte[] inputByteArray = new Byte[strText.Length];
|
|||
|
|
|
|||
|
|
byKey = Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
|
|||
|
|
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|||
|
|
inputByteArray = Convert.FromBase64String(strText);
|
|||
|
|
MemoryStream ms = new MemoryStream();
|
|||
|
|
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
|
|||
|
|
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
|||
|
|
cs.FlushFinalBlock();
|
|||
|
|
Encoding encoding = new UTF8Encoding();
|
|||
|
|
return encoding.GetString(ms.ToArray());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>,ע<><D7A2>strEncrKey<65>ij<EFBFBD><C4B3><EFBFBD>Ϊ8λ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="m_InFilePath"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ļ<EFBFBD>·<EFBFBD><C2B7></param>
|
|||
|
|
/// <param name="m_OutFilePath"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7></param>
|
|||
|
|
/// <param name="strEncrKey"><3E><><EFBFBD>ܼ<EFBFBD></param>
|
|||
|
|
public static void DesEncrypt(string m_InFilePath, string m_OutFilePath, string strEncrKey)
|
|||
|
|
{
|
|||
|
|
byte[] byKey = null;
|
|||
|
|
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
|||
|
|
|
|||
|
|
byKey = Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8));
|
|||
|
|
FileStream fin = new FileStream(m_InFilePath, FileMode.Open, FileAccess.Read);
|
|||
|
|
FileStream fout = new FileStream(m_OutFilePath, FileMode.OpenOrCreate, FileAccess.Write);
|
|||
|
|
fout.SetLength(0);
|
|||
|
|
//Create variables to help with read and write.
|
|||
|
|
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
|
|||
|
|
long rdlen = 0; //This is the total number of bytes written.
|
|||
|
|
long totlen = fin.Length; //This is the total length of the input file.
|
|||
|
|
int len; //This is the number of bytes to be written at a time.
|
|||
|
|
|
|||
|
|
DES des = new DESCryptoServiceProvider();
|
|||
|
|
CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
|
|||
|
|
|
|||
|
|
//Read from the input file, then encrypt and write to the output file.
|
|||
|
|
while (rdlen < totlen)
|
|||
|
|
{
|
|||
|
|
len = fin.Read(bin, 0, 100);
|
|||
|
|
encStream.Write(bin, 0, len);
|
|||
|
|
rdlen = rdlen + len;
|
|||
|
|
}
|
|||
|
|
encStream.Close();
|
|||
|
|
fout.Close();
|
|||
|
|
fin.Close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>,ע<><D7A2>strEncrKey<65>ij<EFBFBD><C4B3><EFBFBD>Ϊ8λ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="m_InFilePath"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ļ<EFBFBD>·<EFBFBD><C2B7></param>
|
|||
|
|
/// <param name="m_OutFilePath"><3E><><EFBFBD><EFBFBD>·<EFBFBD><C2B7></param>
|
|||
|
|
/// <param name="sDecrKey"><3E><><EFBFBD>ܼ<EFBFBD></param>
|
|||
|
|
public static void DesDecrypt(string m_InFilePath, string m_OutFilePath, string sDecrKey)
|
|||
|
|
{
|
|||
|
|
byte[] byKey = null;
|
|||
|
|
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
|||
|
|
|
|||
|
|
byKey = Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
|
|||
|
|
FileStream fin = new FileStream(m_InFilePath, FileMode.Open, FileAccess.Read);
|
|||
|
|
FileStream fout = new FileStream(m_OutFilePath, FileMode.OpenOrCreate, FileAccess.Write);
|
|||
|
|
fout.SetLength(0);
|
|||
|
|
//Create variables to help with read and write.
|
|||
|
|
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
|
|||
|
|
long rdlen = 0; //This is the total number of bytes written.
|
|||
|
|
long totlen = fin.Length; //This is the total length of the input file.
|
|||
|
|
int len; //This is the number of bytes to be written at a time.
|
|||
|
|
|
|||
|
|
DES des = new DESCryptoServiceProvider();
|
|||
|
|
CryptoStream encStream = new CryptoStream(fout, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
|
|||
|
|
|
|||
|
|
//Read from the input file, then encrypt and write to the output file.
|
|||
|
|
while (rdlen < totlen)
|
|||
|
|
{
|
|||
|
|
len = fin.Read(bin, 0, 100);
|
|||
|
|
encStream.Write(bin, 0, len);
|
|||
|
|
rdlen = rdlen + len;
|
|||
|
|
}
|
|||
|
|
encStream.Close();
|
|||
|
|
fout.Close();
|
|||
|
|
fin.Close();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <20>ԳƼ<D4B3><C6BC><EFBFBD><EFBFBD>㷨AES RijndaelManaged<65><64><EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD>
|
|||
|
|
private static readonly string Default_AES_Key = "@#kim123";
|
|||
|
|
private static byte[] Keys = { 0x41, 0x72, 0x65, 0x79, 0x6F, 0x75, 0x6D, 0x79,
|
|||
|
|
0x53,0x6E, 0x6F, 0x77, 0x6D, 0x61, 0x6E, 0x3F };
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ԳƼ<D4B3><C6BC><EFBFBD><EFBFBD>㷨AES RijndaelManaged<65><64><EFBFBD><EFBFBD>(RijndaelManaged<65><64>AES<45><53><EFBFBD>㷨<EFBFBD>ǿ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>㷨)
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="encryptString"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns><3E><><EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|||
|
|
public static string AES_Encrypt(string encryptString)
|
|||
|
|
{
|
|||
|
|
return AES_Encrypt(encryptString, Default_AES_Key);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ԳƼ<D4B3><C6BC><EFBFBD><EFBFBD>㷨AES RijndaelManaged<65><64><EFBFBD><EFBFBD>(RijndaelManaged<65><64>AES<45><53><EFBFBD>㷨<EFBFBD>ǿ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>㷨)
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="encryptString"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="encryptKey"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><D4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD></param>
|
|||
|
|
/// <returns><3E><><EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|||
|
|
public static string AES_Encrypt(string encryptString, string encryptKey)
|
|||
|
|
{
|
|||
|
|
encryptKey = GetSubString(encryptKey, 32, "");
|
|||
|
|
encryptKey = encryptKey.PadRight(32, ' ');
|
|||
|
|
|
|||
|
|
RijndaelManaged rijndaelProvider = new RijndaelManaged();
|
|||
|
|
rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 32));
|
|||
|
|
rijndaelProvider.IV = Keys;
|
|||
|
|
ICryptoTransform rijndaelEncrypt = rijndaelProvider.CreateEncryptor();
|
|||
|
|
|
|||
|
|
byte[] inputData = Encoding.UTF8.GetBytes(encryptString);
|
|||
|
|
byte[] encryptedData = rijndaelEncrypt.TransformFinalBlock(inputData, 0, inputData.Length);
|
|||
|
|
|
|||
|
|
return Convert.ToBase64String(encryptedData);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ԳƼ<D4B3><C6BC><EFBFBD><EFBFBD>㷨AES RijndaelManaged<65><64><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="decryptString"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns><3E><><EFBFBD>ܳɹ<DCB3><C9B9><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>,ʧ<>ܷ<EFBFBD>Դ<EFBFBD><D4B4></returns>
|
|||
|
|
public static string AES_Decrypt(string decryptString)
|
|||
|
|
{
|
|||
|
|
return AES_Decrypt(decryptString, Default_AES_Key);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ԳƼ<D4B3><C6BC><EFBFBD><EFBFBD>㷨AES RijndaelManaged<65><64><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="decryptString"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="decryptKey"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ,<2C>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><D4BF>ͬ</param>
|
|||
|
|
/// <returns><3E><><EFBFBD>ܳɹ<DCB3><C9B9><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>,ʧ<>ܷ<EFBFBD><DCB7>ؿ<EFBFBD></returns>
|
|||
|
|
public static string AES_Decrypt(string decryptString, string decryptKey)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
decryptKey = GetSubString(decryptKey, 32, "");
|
|||
|
|
decryptKey = decryptKey.PadRight(32, ' ');
|
|||
|
|
|
|||
|
|
RijndaelManaged rijndaelProvider = new RijndaelManaged();
|
|||
|
|
rijndaelProvider.Key = Encoding.UTF8.GetBytes(decryptKey);
|
|||
|
|
rijndaelProvider.IV = Keys;
|
|||
|
|
ICryptoTransform rijndaelDecrypt = rijndaelProvider.CreateDecryptor();
|
|||
|
|
|
|||
|
|
byte[] inputData = Convert.FromBase64String(decryptString);
|
|||
|
|
byte[] decryptedData = rijndaelDecrypt.TransformFinalBlock(inputData, 0, inputData.Length);
|
|||
|
|
|
|||
|
|
return Encoding.UTF8.GetString(decryptedData);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ֽڳ<D6BD><DAB3><EFBFBD>(<28><><EFBFBD>ֽ<EFBFBD>,һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ2<CEAA><32><EFBFBD>ֽ<EFBFBD>)ȡ<><C8A1>ij<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sourceString">Դ<>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="length"><3E><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ֽڳ<D6BD><DAB3><EFBFBD></param>
|
|||
|
|
/// <param name="tailString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>(<28><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ϊ"...")</param>
|
|||
|
|
/// <returns>ij<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD></returns>
|
|||
|
|
private static string GetSubString(string sourceString, int length, string tailString)
|
|||
|
|
{
|
|||
|
|
return GetSubString(sourceString, 0, length, tailString);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ֽڳ<D6BD><DAB3><EFBFBD>(<28><><EFBFBD>ֽ<EFBFBD>,һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ2<CEAA><32><EFBFBD>ֽ<EFBFBD>)ȡ<><C8A1>ij<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sourceString">Դ<>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="startIndex"><3E><><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>0<EFBFBD><30>ʼ</param>
|
|||
|
|
/// <param name="length"><3E><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ֽڳ<D6BD><DAB3><EFBFBD></param>
|
|||
|
|
/// <param name="tailString"><3E><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>(<28><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ϊ"...")</param>
|
|||
|
|
/// <returns>ij<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD></returns>
|
|||
|
|
private static string GetSubString(string sourceString, int startIndex, int length, string tailString)
|
|||
|
|
{
|
|||
|
|
string myResult = sourceString;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>ʱ(ע:<3A><><EFBFBD>ĵķ<C4B5>Χ:\u4e00 - \u9fa5, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\u0800 - \u4e00, <20><><EFBFBD><EFBFBD>Ϊ\xAC00-\xD7A3)
|
|||
|
|
if (System.Text.RegularExpressions.Regex.IsMatch(sourceString, "[\u0800-\u4e00]+") ||
|
|||
|
|
System.Text.RegularExpressions.Regex.IsMatch(sourceString, "[\xAC00-\xD7A3]+"))
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʼλ<CABC>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>ֶδ<D6B6><CEB4><EFBFBD><EFBFBD><EFBFBD>ʱ
|
|||
|
|
if (startIndex >= sourceString.Length)
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return sourceString.Substring(startIndex,
|
|||
|
|
((length + startIndex) > sourceString.Length) ? (sourceString.Length - startIndex) : length);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>"<22>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD>abcd123"
|
|||
|
|
if (length <= 0)
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
byte[] bytesSource = Encoding.Default.GetBytes(sourceString);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
|
|||
|
|
if (bytesSource.Length > startIndex)
|
|||
|
|
{
|
|||
|
|
int endIndex = bytesSource.Length;
|
|||
|
|
|
|||
|
|
//<2F><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ȷ<EFBFBD>Χ<EFBFBD><CEA7>
|
|||
|
|
if (bytesSource.Length > (startIndex + length))
|
|||
|
|
{
|
|||
|
|
endIndex = length + startIndex;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>ʱ,ֻȡ<D6BB><C8A1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ľ<EFBFBD>β
|
|||
|
|
length = bytesSource.Length - startIndex;
|
|||
|
|
tailString = "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int[] anResultFlag = new int[length];
|
|||
|
|
int nFlag = 0;
|
|||
|
|
//<2F>ֽڴ<D6BD><DAB4><EFBFBD>127Ϊ˫<CEAA>ֽ<EFBFBD><D6BD>ַ<EFBFBD>
|
|||
|
|
for (int i = startIndex; i < endIndex; i++)
|
|||
|
|
{
|
|||
|
|
if (bytesSource[i] > 127)
|
|||
|
|
{
|
|||
|
|
nFlag++;
|
|||
|
|
if (nFlag == 3)
|
|||
|
|
{
|
|||
|
|
nFlag = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
nFlag = 0;
|
|||
|
|
}
|
|||
|
|
anResultFlag[i] = nFlag;
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>Ϊ˫<CEAA>ֽ<EFBFBD><D6BD>ַ<EFBFBD><D6B7><EFBFBD>һ<EFBFBD><D2BB>
|
|||
|
|
if ((bytesSource[endIndex - 1] > 127) && (anResultFlag[length - 1] == 1))
|
|||
|
|
{
|
|||
|
|
length = length + 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
byte[] bsResult = new byte[length];
|
|||
|
|
Array.Copy(bytesSource, startIndex, bsResult, 0, length);
|
|||
|
|
myResult = Encoding.Default.GetString(bsResult);
|
|||
|
|
myResult = myResult + tailString;
|
|||
|
|
|
|||
|
|
return myResult;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return string.Empty;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="fs"><3E>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="encryptKey"><3E><><EFBFBD>ܼ<EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static CryptoStream AES_EncryptStrream(FileStream fs, string encryptKey)
|
|||
|
|
{
|
|||
|
|
encryptKey = GetSubString(encryptKey, 32, "");
|
|||
|
|
encryptKey = encryptKey.PadRight(32, ' ');
|
|||
|
|
|
|||
|
|
RijndaelManaged rijndaelProvider = new RijndaelManaged();
|
|||
|
|
rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey);
|
|||
|
|
rijndaelProvider.IV = Keys;
|
|||
|
|
|
|||
|
|
ICryptoTransform encrypto = rijndaelProvider.CreateEncryptor();
|
|||
|
|
CryptoStream cytptostreamEncr = new CryptoStream(fs, encrypto, CryptoStreamMode.Write);
|
|||
|
|
return cytptostreamEncr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="fs"><3E>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="decryptKey"><3E><><EFBFBD>ܼ<EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static CryptoStream AES_DecryptStream(FileStream fs, string decryptKey)
|
|||
|
|
{
|
|||
|
|
decryptKey = GetSubString(decryptKey, 32, "");
|
|||
|
|
decryptKey = decryptKey.PadRight(32, ' ');
|
|||
|
|
|
|||
|
|
RijndaelManaged rijndaelProvider = new RijndaelManaged();
|
|||
|
|
rijndaelProvider.Key = Encoding.UTF8.GetBytes(decryptKey);
|
|||
|
|
rijndaelProvider.IV = Keys;
|
|||
|
|
ICryptoTransform Decrypto = rijndaelProvider.CreateDecryptor();
|
|||
|
|
CryptoStream cytptostreamDecr = new CryptoStream(fs, Decrypto, CryptoStreamMode.Read);
|
|||
|
|
return cytptostreamDecr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ָ<EFBFBD><D6B8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="InputFile"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD></param>
|
|||
|
|
/// <param name="OutputFile"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static bool AES_EncryptFile(string InputFile, string OutputFile)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string decryptKey = "www.iqidi.com";
|
|||
|
|
|
|||
|
|
FileStream fr = new FileStream(InputFile, FileMode.Open);
|
|||
|
|
FileStream fren = new FileStream(OutputFile, FileMode.Create);
|
|||
|
|
CryptoStream Enfr = AES_EncryptStrream(fren, decryptKey);
|
|||
|
|
byte[] bytearrayinput = new byte[fr.Length];
|
|||
|
|
fr.Read(bytearrayinput, 0, bytearrayinput.Length);
|
|||
|
|
Enfr.Write(bytearrayinput, 0, bytearrayinput.Length);
|
|||
|
|
Enfr.Close();
|
|||
|
|
fr.Close();
|
|||
|
|
fren.Close();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
//<2F>ļ<EFBFBD><C4BC>쳣
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ѹ<EFBFBD><D1B9>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="InputFile"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD></param>
|
|||
|
|
/// <param name="OutputFile"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static bool AES_DecryptFile(string InputFile, string OutputFile)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string decryptKey = "www.iqidi.com";
|
|||
|
|
FileStream fr = new FileStream(InputFile, FileMode.Open);
|
|||
|
|
FileStream frde = new FileStream(OutputFile, FileMode.Create);
|
|||
|
|
CryptoStream Defr = AES_DecryptStream(fr, decryptKey);
|
|||
|
|
byte[] bytearrayoutput = new byte[1024];
|
|||
|
|
int m_count = 0;
|
|||
|
|
|
|||
|
|
do
|
|||
|
|
{
|
|||
|
|
m_count = Defr.Read(bytearrayoutput, 0, bytearrayoutput.Length);
|
|||
|
|
frde.Write(bytearrayoutput, 0, m_count);
|
|||
|
|
if (m_count < bytearrayoutput.Length)
|
|||
|
|
break;
|
|||
|
|
} while (true);
|
|||
|
|
|
|||
|
|
Defr.Close();
|
|||
|
|
fr.Close();
|
|||
|
|
frde.Close();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
//<2F>ļ<EFBFBD><C4BC>쳣
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region Base64<36><34><EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// Base64<36><34>һ<EFBFBD>Nʹ<4E><CAB9>64<36><34><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ӌ<EFBFBD><D38B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>H<EFBFBD><48><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1>ASCII <20><>Ԫ<EFBFBD><D4AA>
|
|||
|
|
/// <20>@ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD>Á<EFBFBD><C381><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]<5D><><EFBFBD>Ă<EFBFBD>ݔ<EFBFBD><DD94><EFBFBD>a<EFBFBD><61><EFBFBD><EFBFBD>Base64<36>е<EFBFBD>׃<EFBFBD><D783>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ԪA-Z<><5A>a-z<><7A>0-9 <20><>
|
|||
|
|
/// <20>@<40>ӹ<EFBFBD><D3B9><EFBFBD>62<36><32><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>Á<EFBFBD><C381><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_ʼ<5F><CABC>64<36><34><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɂ<EFBFBD><C982>Á<EFBFBD><C381><EFBFBD><EFBFBD>锵<EFBFBD>ֵķ<D6B5>̖<EFBFBD>ڲ<EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
|
/// ϵ<>y<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
|
/// Base64<36><34><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="str">Base64<36><34>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string Base64Encrypt(string str)
|
|||
|
|
{
|
|||
|
|
byte[] encbuff = System.Text.Encoding.UTF8.GetBytes(str);
|
|||
|
|
return Convert.ToBase64String(encbuff);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Base64<36><34><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="str"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string Base64Decrypt(string str)
|
|||
|
|
{
|
|||
|
|
byte[] decbuff = Convert.FromBase64String(str);
|
|||
|
|
return System.Text.Encoding.UTF8.GetString(decbuff);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region MD5<44><35><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʹ<><CAB9>MD5<44><35><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strText"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns>MD5<44><35><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|||
|
|
public static string MD5Encrypt(string strText)
|
|||
|
|
{
|
|||
|
|
MD5 md5 = new MD5CryptoServiceProvider();
|
|||
|
|
byte[] result = md5.ComputeHash(Encoding.Default.GetBytes(strText));
|
|||
|
|
return Encoding.Default.GetString(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʹ<><CAB9>MD5<44><35><EFBFBD>ܵ<EFBFBD>Hash<73><68>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string MD5EncryptHash(String input)
|
|||
|
|
{
|
|||
|
|
MD5 md5 = new MD5CryptoServiceProvider();
|
|||
|
|
//the GetBytes method returns byte array equavalent of a string
|
|||
|
|
byte[] res = md5.ComputeHash(Encoding.Default.GetBytes(input), 0, input.Length);
|
|||
|
|
char[] temp = new char[res.Length];
|
|||
|
|
//copy to a char array which can be passed to a String constructor
|
|||
|
|
Array.Copy(res, temp, res.Length);
|
|||
|
|
//return the result as a string
|
|||
|
|
return new String(temp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʹ<><CAB9>Md5<64><35><EFBFBD><EFBFBD>Ϊ16<31><36><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string MD5EncryptHashHex(String input)
|
|||
|
|
{
|
|||
|
|
MD5 md5 = new MD5CryptoServiceProvider();
|
|||
|
|
//the GetBytes method returns byte array equavalent of a string
|
|||
|
|
byte[] res = md5.ComputeHash(Encoding.Default.GetBytes(input), 0, input.Length);
|
|||
|
|
|
|||
|
|
String returnThis = string.Empty;
|
|||
|
|
|
|||
|
|
for (int i = 0; i < res.Length; i++)
|
|||
|
|
{
|
|||
|
|
returnThis += Uri.HexEscape((char)res[i]);
|
|||
|
|
}
|
|||
|
|
returnThis = returnThis.Replace("%", "");
|
|||
|
|
returnThis = returnThis.ToLower();
|
|||
|
|
|
|||
|
|
return returnThis;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// MD5 <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD><EFBFBD>㷨.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: (QQʹ<51><CAB9>)
|
|||
|
|
/// 1. <20><>֤<EFBFBD><D6A4>תΪ<D7AA><CEAA>д
|
|||
|
|
/// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD><CEBC>ܺ<EFBFBD>,<2C><><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
|
|||
|
|
/// 3. Ȼ<><EFBFBD><F3BDABB5>Ӻ<EFBFBD><D3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD>MD5һ<35><D2BB>,<2C>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="s"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string EncyptMD5_3_16(string s)
|
|||
|
|
{
|
|||
|
|
MD5 md5 = MD5CryptoServiceProvider.Create();
|
|||
|
|
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(s);
|
|||
|
|
byte[] bytes1 = md5.ComputeHash(bytes);
|
|||
|
|
byte[] bytes2 = md5.ComputeHash(bytes1);
|
|||
|
|
byte[] bytes3 = md5.ComputeHash(bytes2);
|
|||
|
|
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
foreach (var item in bytes3)
|
|||
|
|
{
|
|||
|
|
sb.Append(item.ToString("x").PadLeft(2, '0'));
|
|||
|
|
}
|
|||
|
|
return sb.ToString().ToUpper();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// SHA256<35><36><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="str">ԭʼ<D4AD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns>SHA256<35><36><EFBFBD><EFBFBD>(<28><><EFBFBD>س<EFBFBD><D8B3><EFBFBD>Ϊ44<34>ֽڵ<D6BD><DAB5>ַ<EFBFBD><D6B7><EFBFBD>)</returns>
|
|||
|
|
public static string SHA256(string str)
|
|||
|
|
{
|
|||
|
|
byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
|
|||
|
|
SHA256Managed Sha256 = new SHA256Managed();
|
|||
|
|
byte[] Result = Sha256.ComputeHash(SHA256Data);
|
|||
|
|
return Convert.ToBase64String(Result); //<2F><><EFBFBD>س<EFBFBD><D8B3><EFBFBD>Ϊ44<34>ֽڵ<D6BD><DAB5>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string EncryptString(string input)
|
|||
|
|
{
|
|||
|
|
return MD5Utils.AddMD5Profix(Base64Util.Encrypt(MD5Utils.AddMD5Profix(input)));
|
|||
|
|
//return Base64.Encrypt(MD5.AddMD5Profix(Base64.Encrypt(input)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ܼӹ<DCBC><D3B9>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input"><3E><><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <param name="throwException"><3E><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>쳣</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string DecryptString(string input, bool throwException)
|
|||
|
|
{
|
|||
|
|
string res = "";
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
res = input;// Base64.Decrypt(input);
|
|||
|
|
if (MD5Utils.ValidateValue(res))
|
|||
|
|
{
|
|||
|
|
return MD5Utils.RemoveMD5Profix(Base64Util.Decrypt(MD5Utils.RemoveMD5Profix(res)));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
throw new Exception("<22>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
if (throwException)
|
|||
|
|
{
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|