1、方法一 (不可逆加密)
public string encryptpassword(string passwordstring,string passwordformat )
elseif (passwordformat="md5")
return encryptpassword ;
}2、方法二 (可逆加密)
public inte***ce ibindesh
public class encryptiondecryption : ibindesh
return htext;
}public string decode(string str)
return dtext;
}3、方法三 (可逆加密)
descryptoserviceprovider cryptoprovider = new descryptoserviceprovider();
int i = cryptoprovider.keysize;
memorystream ms = new memorystream();
cryptostream cst = new cryptostream(ms, cryptoprovider.createencryptor(bykey,
byiv), cryptostreammode.write);
streamwriter sw = new streamwriter(cst);
sw.write(data);
sw.flush();
cst.flushfinalblock();
sw.flush();
return convert.tobase64string(ms.getbuffer(), 0, (int)ms.length);
public string decode(string data)
catch
descryptoserviceprovider cryptoprovider = new descryptoserviceprovider();
memorystream ms = new memorystream(byenc);
cryptostream cst = new cryptostream(ms, cryptoprovider.createdecryptor(bykey,
byiv), cryptostreammode.read);
streamreader sr = new streamreader(cst);
return sr.readtoend();
}4、md5不可逆加密
(32位加密)
public string ge***5(string s, string _input_charset)
5、加解文字檔案
//加密檔案
private static void encryptdata(string inname, string outname, byte deskey, byte
desiv)
encstream.close();
fout.close();
fin.close();
}//解密檔案
private static void decryptdata(string inname, string outname, byte deskey, byte
desiv)
encstream.close();
fout.close();
fin.close();}6、
using system;
using system.collections.generic;
using system.text;
using system.security.cryptography;
using system.io;
namespace component
//預設金鑰向量
private static byte keys = ;
/**//**//**//**//**//**//**
/// des加密字串
///
/// 待加密的字串
/// 加密金鑰,要求為8位
/// 加密成功返回加密後的字串,失敗返回源串
public static string encryptdes(string encryptstring, string encryptkey)
catch
}/**//**//**//**//**//**//**
/// des解密字串
///
/// 待解密的字串
/// 解密金鑰,要求為8位,和加密金鑰相同
/// 解密成功返回解密後的字串,失敗返源串
public static string decryptdes(string decryptstring, string decryptkey)
catch}}
}
C 加密解密方法匯集
1 方法一 不可逆加密 2 方法二 可逆加密 3 方法三 可逆加密 public string encode string data public string decode string data catch descryptoserviceprovider cryptoprovider new ...
C 中加密解密方法
下面是寫好的方法,使用時直接呼叫即可 using system using system.io using system.security.cryptography namespace csharplibrary.staticservice 加密 引數 strdata 要加密的資料 strkey 金...
C 加密解密
using system using system.text using system.globalization using system.security.cryptography class des 加密字串 public string encryptstring string sinputs...