DES 加密解密字串

2021-09-13 18:29:42 字數 2038 閱讀 9592

/// /// 字串如果操過指定長度則將超出的部分用指定字串代替

///

/// 要檢查的字串

/// 指定長度

/// 用於替換的字串

/// 擷取後的字串

private static string getsubstring(string p_srcstring, int p_length, string p_tailstring)

/// /// 取指定長度的字串

///

/// 要檢查的字串

/// 起始位置

/// 指定長度

/// 用於替換的字串

/// 擷取後的字串

private static string getsubstring(string p_srcstring, int p_startindex, int p_length, string p_tailstring)

}if (p_length >= 0)

else

int nreallength = p_length;

int anresultflag = new int[p_length];

byte bsresult = null;

int nflag = 0;

for (int i = p_startindex; i < p_endindex; i++)

else

nflag = 0;

anresultflag[i] = nflag;

}if ((bssrcstring[p_endindex - 1] > 127) && (anresultflag[p_length - 1] == 1))

nreallength = p_length + 1;

bsresult = new byte[nreallength];

array.copy(bssrcstring, p_startindex, bsresult, 0, nreallength);

myresult = encoding.default.getstring(bsresult);

myresult = myresult + p_tailstring;}}

return myresult;

}//預設金鑰向量

private static readonly byte keys = ;

/// /// des加密字串

///

/// 待加密的字串

/// 加密金鑰,要求為8位

/// 加密成功返回加密後的字串,失敗返回源串

public static string desencode(string encryptstring, string encryptkey)

/// /// des加密字串

///

/// 待加密的字串

/// 加密金鑰,要求為8位

/// 加密成功返回加密後的字串,失敗返回源串

public static string desencode(string encryptstring, string encryptkey, encoding encoding)

/// /// des解密字串

///

/// 待解密的字串

/// 解密金鑰,要求為8位,和加密金鑰相同

/// 解密成功返回解密後的字串,失敗返源串

public static string desdecode(string decryptstring, string decryptkey)

catch

}/// /// des解密字串

///

/// 待解密的字串

/// 解密金鑰,要求為8位,和加密金鑰相同

/// 解密成功返回解密後的字串,失敗返源串

public static string desdecode(string decryptstring, string decryptkey, encoding encoding)

catch

}

DES加密解密字串

金鑰隨機生成 class des 建立key public string generatekey descryptoserviceprovider descrypto descryptoserviceprovider descryptoserviceprovider.create return as...

C 對字串加密解密 DES

using system using system.collections.generic using system.linq using system.text using system.security using system.security.cryptography using syste...

C 對字串加密解密 DES

using system using system.collections.generic using system.linq using system.text using system.security using system.security.cryptography using syste...