DES資料加密 解密

2022-05-04 21:39:32 字數 1274 閱讀 1500

///

/// des資料加密

///

/// 目標值

/// 金鑰

/// 加密值

public static string encrypt(string targetvalue, string key)

///

///

///

public static string decrypt(string targetvalue, string key)

// 定義des加密物件

var des = new descryptoserviceprovider();

int len = targetvalue.length / 2;

var inputbytearray = new byte[len];

int x, i;

for (x = 0; x < len; x++)

// 通過兩次雜湊密碼設定對稱演算法的初始化向量

des.key = encoding.ascii.getbytes(formsauthentication.hashpasswordforstoringinconfigfile

(formsauthentication.hashpasswordforstoringinconfigfile(key, "md5").

substring(0, 8), "sha1").substring(0, 8));

// 通過兩次雜湊密碼設定演算法的機密金鑰

des.iv = encoding.ascii.getbytes(formsauthentication.hashpasswordforstoringinconfigfile

(formsauthentication.hashpasswordforstoringinconfigfile(key, "md5")

.substring(0, 8), "md5").substring(0, 8));

// 定義記憶體流

var ms = new memorystream();

// 定義加密流

var cs = new cryptostream(ms, des.createdecryptor(), cryptostreammode.write);

cs.write(inputbytearray, 0, inputbytearray.length);

cs.flushfinalblock();

return encoding.default.getstring(ms.toarray());

}

DES加密解密

using system using system.drawing using system.collections using system.componentmodel using system.windows.forms using system.data using system.io us...

DES加密解密

加密類 date 2012 04 23 pm.public class encrypt private encrypt 建立加密類物件.public static encrypt createcryptoserviceprovider des加密.待加密字串.加密金鑰.8位 public strin...

DES加密解密

using system.data using system.configuration using system.web using system.web.security using system.web.ui using system.web.ui.webcontrols using syst...