C 常用資料加密類

2021-09-07 04:14:09 字數 4818 閱讀 9549

using system;

using system.collections.generic;

using system.io;

using system.linq;

using system.security.cryptography;

using system.text;

using system.threading.tasks;

namespace cryptography

if (string.isnullorempty(encryptkey))

if (encryptkey.length != 8)

byte m_btiv = ;

string m_strencrypt = "";

descryptoserviceprovider m_desprovider = new descryptoserviceprovider();

trycatch (ioexception ex)

catch (cryptographicexception ex)

catch (argumentexception ex)

catch (exception ex)

finally

return m_strencrypt;

} #endregion

#region des 解密(資料加密標準,速度較快,適用於加密大量資料的場合)

/// /// des 解密(加密速度較快,適用於加密大量資料的場合)

///

/// 待解密的密文

/// 解密的金鑰

/// returns

public static string desdecrypt(string decryptstring, string decryptkey)

if (string.isnullorempty(decryptkey))

if (decryptkey.length != 8)

byte m_btiv = ;

string m_strdecrypt = "";

descryptoserviceprovider m_desprovider = new descryptoserviceprovider();

trycatch (ioexception ex)

catch (cryptographicexception ex)

catch (argumentexception ex)

catch (exception ex)

finally

return m_strdecrypt;

} #endregion

#region rc2 加密(用變長金鑰對大量資料進行加密)

/// /// rc2 加密(用變長金鑰對大量資料進行加密)

///

/// 待加密密文

/// 加密金鑰

/// returns

public static string rc2encrypt(string encryptstring, string encryptkey)

if (string.isnullorempty(encryptkey))

if (encryptkey.length < 5 || encryptkey.length > 16)

string m_strencrypt = "";

byte m_btiv = ;

rc2cryptoserviceprovider m_rc2provider = new rc2cryptoserviceprovider();

trycatch (ioexception ex)

catch (cryptographicexception ex)

catch (argumentexception ex)

catch (exception ex)

finally

return m_strencrypt;

} #endregion

#region rc2 解密(用變長金鑰對大量資料進行加密)

/// /// rc2 解密(用變長金鑰對大量資料進行加密)

///

/// 待解密密文

/// 解密金鑰

/// returns

public static string rc2decrypt(string decryptstring, string decryptkey)

if (string.isnullorempty(decryptkey))

if (decryptkey.length < 5 || decryptkey.length > 16)

byte m_btiv = ;

string m_strdecrypt = "";

rc2cryptoserviceprovider m_rc2provider = new rc2cryptoserviceprovider();

trycatch (ioexception ex)

catch (cryptographicexception ex)

catch (argumentexception ex)

catch (exception ex)

finally

return m_strdecrypt;

} #endregion

#region 3des加密基於des,對一塊資料用三個不同的秘鑰進行三次加密,強度更高些

/// /// 3des加密基於des,對一塊資料用三個不同的金鑰進行三次加密,強度更高些

///

/// 待加密密文

/// 金鑰一

/// 金鑰二

/// 金鑰三

/// returns

public static string des3encrypt(string encryptstring, string encryptkey1, string encryptkey2, string encryptkey3)

catch (exception ex)

return m_strencrypt;

} #endregion

#region 3des 解密(3des加密基於des,對一塊資料用三個不同的金鑰進行三次加密,強度更高些)

/// /// 3des 解密(3des加密基於des,對一塊資料用三個不同的金鑰進行三次加密,強度更高些)

///

/// 待解密密文

/// 金鑰一

/// 金鑰二

/// 金鑰三

/// returns

public static string des3decrypt(string decryptstring, string decryptkey1, string decryptkey2, string decryptkey3)

catch (exception ex)

return m_strdecrypt;

} #endregion

#region aes 加密為高階加密標準,是下一代加密演算法的標準,速度快,安全級別高

/// /// aes 加密為高階加密標準,是下一代加密演算法的標準,速度快,安全級別高

///

/// 待加密密文

/// 加密金鑰

///

public static string aesencrypt(string encryptstring, string encryptkey)

if (string.isnullorempty(encryptkey))

string m_strencrypt = "";

byte m_btiv = convert.frombase64string("rkb4jvuy/ye7cd7k89qqgq==");

rijndael m_aesprovider = rijndael.create();

trycatch (ioexception ex)

catch (cryptographicexception ex)

catch (argumentexception ex)

catch (exception ex)

finally

return m_strencrypt;

} #endregion

#region aes 加密為高階加密標準,是下一代加密演算法的標準,速度快,安全級別高

/// /// aes 加密為高階加密標準,是下一代加密演算法的標準,速度快,安全級別高

///

/// 待解密密文

/// 解密金鑰

///

public static string aesdecrypt(string decryptstring, string decryptkey)

if (string.isnullorempty(decryptkey))

string m_strdecrypt = "";

byte m_btiv = convert.frombase64string("rkb4jvuy/ye7cd7k89qqgq==");

rijndael m_aesprovider = rijndael.create();

trycatch (ioexception ex)

catch (cryptographicexception ex)

catch (argumentexception ex)

catch (exception ex)

finally

return m_strdecrypt;

} #endregion

}}

C 常用工具類 加密解密類

using system using system.configuration using system.collections.generic using system.text using system.web using system.web.ui using system.web.ui.ht...

C 可逆加密類

using system using system.collections.generic using system.linq using system.text using system.io using system.security.cryptography namespace fromarg...

C 常用資料檢查類

using system using system.text using system.web using system.web.ui.webcontrols using system.text.regularexpressions namespace legalsoft.wizard.basic ...