關於配置檔案內容加密處理的感想

2021-06-27 23:46:11 字數 1420 閱讀 4582

前幾天,公司提了乙個需求,及讓我們將資料庫及伺服器的路徑做加密處理。這對於才接觸工作的我來說,著實讓我頭疼半天。說實話,我一開始完全沒想過加密問題,直到上次讓我用3des加密技術,對使用者名稱和密碼等做加密處理時稍微了解了一下。先說下3des,這是對稱加密演算法,所謂對稱加密,我的理解就是,加密解密通用乙個密匙。

以下是3des對字串的處理**:

public class threedes

catch (exception e)

}/**

* 加密string明文輸入,string密文輸出

* * @param strming

* @return

*/public static string getencstring(string strming)

catch (exception e)

return strmi;

}/**

* 解密 以string密文輸入,string明文輸出

* * @param strmi

* @return

*/public static string getdesstring(string strmi)

catch (exception e)

return strming;

}/**

* 加密以byte明文輸入,byte密文輸出

* * @param bytes

* @return

*/private static byte getenccode(byte bytes)

catch (exception e)

finally

return bytefina;

}/**

* 解密以byte密文輸入,以byte明文輸出

* * @param byted

* @return

*/private static byte getdescode(byte byted)

catch (exception e)

finally

return bytefina;

}/**

* 二行制轉字串

* * @param b

* @return

*/public static string byte2hex(byte b)

return hs.touppercase(); // 轉成大寫

}public static byte hex2byte(byte b)

return b2;

}這是我查到的可以用於字串之間的轉換的方法。

起初我找到的是將其轉換成位元組陣列然後根據16進製制密匙處理得到的新的位元組陣列,但這個方法有乙個缺點就是轉換回原來的字串必須得傳位元組陣列,而我們將打亂後的字串轉成位元組陣列後,則一直報錯,後來查原因發現是因為轉碼前後的位元組陣列長度不一樣。因此和我們的需求相形甚遠。

關於配置檔案的節點內容加密(備忘)

在這裡呢,將要介紹一種加密 web.config 檔案中節的方法,就是 dpapi 也就是使用 dataprotectionconfigurationprovider 來實現,其實呢,還有一種加密的演算法,叫做 rsa 加密演算法,不過在實現上這個 rsa 和 dpapi 差不多,所以只要注意看一下...

Spring配置檔案內容加密

spring框架在一些對安全性要求較高的生產環境下,配置檔案不允許出現明文使用者名稱密碼配置,如資料庫配置等。本文主要用於解決明文使用者名稱密碼加密。public class encryptpropertyplaceholderconfigurer extends propertyplacehold...

C 配置檔案加密

以管理員的身份執行 vs 開發人員命令提示 aspnet regiis.exe pef 配置節 專案路徑 例如 aspnet regiis.exe pef connectionstrings c myweb helloservice prov dataprotectionconfigurationp...