很简单的加密解密,但不知道有没有版权哟。我也是原文转抄别人的,贴出来给大家看看。^_^using System;namespace Watchdog
{
/// <summary>
/// EnCryptAndDeCrypt 的摘要说明。
/// </summary>
public class EnCryptAndDeCrypt
{
private String g_Key;  //加密的钥匙
private String strContent;    //要加密的内容
private static int  iKeyLength=256; //密钥的长度 public EnCryptAndDeCrypt() 
{ } public String Key
{
set
{
g_Key=value;
} get
{
return g_Key;
}
} /**
* 加密
* @param strEncrypted:需要加密的字符串
* @return:加密过后的字符串
*/
public string EnCrypt(String strCryptThis)
{ String strEncrypted="";
char strChar,iCryptChar, iKeyChar, iStringChar;
for(int i=0;i<strCryptThis.Length;i++)
{
iKeyChar=g_Key[i];
iStringChar=strCryptThis[i];
iCryptChar=(char)(iKeyChar^iStringChar);
strEncrypted =  strEncrypted + iCryptChar;
} return strEncrypted;
} /**
 * 解密
 * @param strEncrypted:需要解密的字符串
 * @return:解密过后的字符串
 */
public String DeCrypt(String strEncrypted)
{
char strChar, iKeyChar, iStringChar,iDeCryptChar;
String strDecrypted="";
for(int i=0;i<strEncrypted.Length;i++)
{
iKeyChar=g_Key[i];
iStringChar=strEncrypted[i];
iDeCryptChar=(char)(iKeyChar^iStringChar);
strDecrypted=strDecrypted + iDeCryptChar;
} return strDecrypted;
} /**
 * 生成本次加密或解密的钥匙
 * @return
 */ public static String KeyGeN()
{
int k;
int iCount;
String strMyKey="";
int lowerbound = 65;
int upperbound = 96;
Random rd=new Random();
for(int i=1;i<iKeyLength;i++)
{  
            //rd=new Random(i);
//k =(int)(((upperbound - lowerbound) + 1)* rd.Next() + lowerbound; k=(int)rd.Next(lowerbound,upperbound);
strMyKey=strMyKey + (char)k; }
           
return strMyKey;
} /**
 * 测试
 * @param args
 
public static void main(String[] args)
{
String key=EnCryptAndDeCrypt.KeyGeN();
String str="I am stone.xxxx sdfsdfsd.,dffsdfsdfsdf sdfwe3e";
EnCryptAndDeCrypt test=new EnCryptAndDeCrypt(); test.setKey(key);
System.out.println(test.EnCrypt(str));
System.out.println(test.DeCrypt(test.EnCrypt(str)));
}

*/
}

}

解决方案 »

  1.   

    楼主,我已经给你发了一个文件,叫Function.cs,里面有一个Function类,你直接加入到你的项目中,然后using MyFunction,然后直接用Function.xxx("xxx")用就行了,里面有很多静态方法,其中就有加密的。
      

  2.   

    看这个帖子中我的回答:http://expert.csdn.net/Expert/topic/1237/1237771.xml?temp=.1235468
      

  3.   

    给你发过去了,看看吧,Base64的。
      

  4.   

    DES加密类:
    FileStream fs  = new FileStream("EncryptedFile.txt",FileMode.Create,FileAccess.Write);
    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    ICryptoTransform desencrypt = des.CreateEncryptor();
    CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Write);
    cryptostream.Write(bytearrayinput,0,bytearrayinput.Length);
    cryptostream.Close();
    Dim fs As New FileStream("EncryptedFile.txt", FileMode.Create, FileAccess.Write)
    Dim des As New DESCryptoServiceProvider()
    Dim desencrypt As ICryptoTransform = des.CreateEncryptor()
    Dim cryptostream As New CryptoStream(fs, desencrypt, CryptoStreamMode.Write)
    cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
    cryptostream.Close()