用于许可证加密和解密的部分代码。
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace BaiRong.Core.Cryptography
{
public class DESEncryptor
{
private string decryptKey;
private string encryptKey;
private string inputFilePath;
private string inputString;
private string noteMessage;
private string outFilePath;
private string outString;
public string DecryptKey
{
get
{
return decryptKey;
}
set
{
decryptKey = value;
}
}
public string EncryptKey
{
get
{
return encryptKey;
}
set
{
encryptKey = value;
}
}
public string InputFilePath
{
get
{
return inputFilePath;
}
set
{
inputFilePath = value;
}
}
public string InputString
{
get
{
return inputString;
}
set
{
inputString = value;
}
}
public string NoteMessage
{
get
{
return noteMessage;
}
set
{
noteMessage = value;
}
}
public string OutFilePath
{
get
{
return outFilePath;
}
set
{
outFilePath = value;
}
}
public string OutString
{
get
{
return outString;
}
set
{
outString = value;
}
}
public DESEncryptor()
{
inputString = null;
outString = null;
inputFilePath = null;
outFilePath = null;
encryptKey = null;
decryptKey = null;
noteMessage = null;
}
public void DesDecrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] bArr3 = new [inputString.Length];
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, 8));
System.Security.Cryptography.DESCryptoServiceProvider descryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider();
bArr3 = System.Convert.FromBase64String(inputString);
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, descryptoServiceProvider.CreateDecryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
cryptoStream.Write(bArr3, 0, bArr3.Length);
cryptoStream.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
outString = encoding.GetString(memoryStream.ToArray());
}
catch (System.Exception e)
{
noteMessage = e.Message;
}
}
public void DesEncrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
System.Security.Cryptography.DESCryptoServiceProvider descryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider();
byte[] bArr3 = System.Text.Encoding.UTF8.GetBytes(inputString);
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, descryptoServiceProvider.CreateEncryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
cryptoStream.Write(bArr3, 0, bArr3.Length);
cryptoStream.FlushFinalBlock();
outString = System.Convert.ToBase64String(memoryStream.ToArray());
}
catch (System.Exception e)
{
noteMessage = e.Message;
}
}
public void FileDesDecrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, 8));
System.IO.FileStream fileStream1 = new System.IO.FileStream(inputFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream fileStream2 = new System.IO.FileStream(outFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
fileStream2.SetLength((long)0);
byte[] bArr3 = new [0x64];
long l1 = (long)0;
long l2 = fileStream1.Length;
System.Security.Cryptography.DES des = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(fileStream2, des.CreateDecryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
while (l1 < l2)
{
int i = fileStream1.Read(bArr3, 0, 0x64);
cryptoStream.Write(bArr3, 0, i);
l1 += (long)i;
}
cryptoStream.Close();
fileStream2.Close();
fileStream1.Close();
}
catch (System.Exception e)
{
noteMessage = e.Message.ToString();
}
}
public void FileDesEncrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x44, 0x16, 0xEE, 0x88, 0x15, 0xDD, 0x41 };
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
System.IO.FileStream fileStream1 = new System.IO.FileStream(inputFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream fileStream2 = new System.IO.FileStream(outFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
fileStream2.SetLength((long)0);
byte[] bArr3 = new [0x64];
long l1 = (long)0;
long l2 = fileStream1.Length;
System.Security.Cryptography.DES des = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(fileStream2, des.CreateEncryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
while (l1 < l2)
{
int i = fileStream1.Read(bArr3, 0, 0x64);
cryptoStream.Write(bArr3, 0, i);
l1 += (long)i;
}
cryptoStream.Close();
fileStream2.Close();
fileStream1.Close();
}
catch (System.Exception e)
{
noteMessage = e.Message.ToString();
}
}
public void MD5Encrypt()
{
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bArr = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(inputString));
outString = System.Text.Encoding.Default.GetString(bArr);
}
} // class DESEncryptor
}
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace BaiRong.Core.Cryptography
{
public class DESEncryptor
{
private string decryptKey;
private string encryptKey;
private string inputFilePath;
private string inputString;
private string noteMessage;
private string outFilePath;
private string outString;
public string DecryptKey
{
get
{
return decryptKey;
}
set
{
decryptKey = value;
}
}
public string EncryptKey
{
get
{
return encryptKey;
}
set
{
encryptKey = value;
}
}
public string InputFilePath
{
get
{
return inputFilePath;
}
set
{
inputFilePath = value;
}
}
public string InputString
{
get
{
return inputString;
}
set
{
inputString = value;
}
}
public string NoteMessage
{
get
{
return noteMessage;
}
set
{
noteMessage = value;
}
}
public string OutFilePath
{
get
{
return outFilePath;
}
set
{
outFilePath = value;
}
}
public string OutString
{
get
{
return outString;
}
set
{
outString = value;
}
}
public DESEncryptor()
{
inputString = null;
outString = null;
inputFilePath = null;
outFilePath = null;
encryptKey = null;
decryptKey = null;
noteMessage = null;
}
public void DesDecrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] bArr3 = new [inputString.Length];
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, 8));
System.Security.Cryptography.DESCryptoServiceProvider descryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider();
bArr3 = System.Convert.FromBase64String(inputString);
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, descryptoServiceProvider.CreateDecryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
cryptoStream.Write(bArr3, 0, bArr3.Length);
cryptoStream.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
outString = encoding.GetString(memoryStream.ToArray());
}
catch (System.Exception e)
{
noteMessage = e.Message;
}
}
public void DesEncrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
System.Security.Cryptography.DESCryptoServiceProvider descryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider();
byte[] bArr3 = System.Text.Encoding.UTF8.GetBytes(inputString);
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(memoryStream, descryptoServiceProvider.CreateEncryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
cryptoStream.Write(bArr3, 0, bArr3.Length);
cryptoStream.FlushFinalBlock();
outString = System.Convert.ToBase64String(memoryStream.ToArray());
}
catch (System.Exception e)
{
noteMessage = e.Message;
}
}
public void FileDesDecrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, 8));
System.IO.FileStream fileStream1 = new System.IO.FileStream(inputFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream fileStream2 = new System.IO.FileStream(outFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
fileStream2.SetLength((long)0);
byte[] bArr3 = new [0x64];
long l1 = (long)0;
long l2 = fileStream1.Length;
System.Security.Cryptography.DES des = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(fileStream2, des.CreateDecryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
while (l1 < l2)
{
int i = fileStream1.Read(bArr3, 0, 0x64);
cryptoStream.Write(bArr3, 0, i);
l1 += (long)i;
}
cryptoStream.Close();
fileStream2.Close();
fileStream1.Close();
}
catch (System.Exception e)
{
noteMessage = e.Message.ToString();
}
}
public void FileDesEncrypt()
{
byte[] bArr1 = null;
byte[] bArr2 = new byte[] { 0x12, 0x44, 0x16, 0xEE, 0x88, 0x15, 0xDD, 0x41 };
try
{
bArr1 = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
System.IO.FileStream fileStream1 = new System.IO.FileStream(inputFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream fileStream2 = new System.IO.FileStream(outFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
fileStream2.SetLength((long)0);
byte[] bArr3 = new [0x64];
long l1 = (long)0;
long l2 = fileStream1.Length;
System.Security.Cryptography.DES des = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.CryptoStream cryptoStream = new System.Security.Cryptography.CryptoStream(fileStream2, des.CreateEncryptor(bArr1, bArr2), System.Security.Cryptography.CryptoStreamMode.Write);
while (l1 < l2)
{
int i = fileStream1.Read(bArr3, 0, 0x64);
cryptoStream.Write(bArr3, 0, i);
l1 += (long)i;
}
cryptoStream.Close();
fileStream2.Close();
fileStream1.Close();
}
catch (System.Exception e)
{
noteMessage = e.Message.ToString();
}
}
public void MD5Encrypt()
{
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bArr = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(inputString));
outString = System.Text.Encoding.Default.GetString(bArr);
}
} // class DESEncryptor
}
调用部分代码
private static XmlDocument a(string A_0)
{
XmlDocument document = new XmlDocument();
try
{
DESEncryptor encryptor = new DESEncryptor();
encryptor.set_InputString(FileUtils.ReadBase64StringFromFile(A_0));
encryptor.set_DecryptKey("kesgf4zb");
encryptor.DesDecrypt();
string xml = encryptor.get_OutString().Substring(encryptor.get_OutString().IndexOf("\r\n") + 2);
document.LoadXml(xml);
}
catch
{
}
return document;
}
{
XmlDocument document = new XmlDocument();
try
{
DESEncryptor encryptor = new DESEncryptor();
encryptor.set_InputString(FileUtils.ReadBase64StringFromFile(A_0));
encryptor.set_DecryptKey("kesgf4zb");
encryptor.DesDecrypt();
string xml = encryptor.get_OutString().Substring(encryptor.get_OutString().IndexOf("\r\n") + 2);
document.LoadXml(xml);
}
catch
{
}
return document;
}
浙公网安备 33010602011771号