這篇文章主要講解了“怎么用對(duì)稱加密算法實(shí)現(xiàn)C#數(shù)據(jù)加密”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么用對(duì)稱加密算法實(shí)現(xiàn)C#數(shù)據(jù)加密”吧!
在義縣等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)營(yíng)銷推廣,外貿(mào)營(yíng)銷網(wǎng)站建設(shè),義縣網(wǎng)站建設(shè)費(fèi)用合理。
以下是關(guān)于對(duì)稱加密算法的C#數(shù)據(jù)加密實(shí)現(xiàn)代碼,大家可以根據(jù)需要更改不同的算法,文中以Rijndael算法為例:
using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace DataCrypto { /// /// C#數(shù)據(jù)加密對(duì)稱加密算法類 /// public class SymmetricMethod { private SymmetricAlgorithm mobjCryptoService; private string Key; /// /// 對(duì)稱加密類的C#數(shù)據(jù)加密 /// public SymmetricMethod() { mobjCryptoService = new RijndaelManaged(); Key = "Guz(%&hj7x89H$yuBI0456FtmaT5&fvHUFCy76*h%(HilJ$lhj!y6&(*jkP87jH7"; } /// /// 獲得密鑰 /// /// 密鑰 private byte[] GetLegalKey() { string sTemp = Key; mobjCryptoService.GenerateKey(); byte[] bytTemp = mobjCryptoService.Key; int KeyLength = bytTemp.Length; if (sTemp.Length > KeyLength) sTemp = sTemp.Substring(0, KeyLength); else if (sTemp.Length < KeyLength) sTemp = sTemp.PadRight(KeyLength, ' '); return ASCIIEncoding.ASCII.GetBytes(sTemp); } /// /// 獲得初始向量IV /// /// 初試向量IV private byte[] GetLegalIV() { string sTemp = "E4ghj*Ghg7!rNIfb&95GUY86GfghUb#er57HBh(u%g6HJ($jhWk7&!hg4ui%$hjk"; mobjCryptoService.GenerateIV(); byte[] bytTemp = mobjCryptoService.IV; int IVLength = bytTemp.Length; if (sTemp.Length > IVLength) sTemp = sTemp.Substring(0, IVLength); else if (sTemp.Length < IVLength) sTemp = sTemp.PadRight(IVLength, ' '); return ASCIIEncoding.ASCII.GetBytes(sTemp); } /// /// 加密方法 /// /// 待加密的串 /// 經(jīng)過(guò)加密的串 public string Encrypto(string Source) { byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source); MemoryStream ms = new MemoryStream();
感謝各位的閱讀,以上就是“怎么用對(duì)稱加密算法實(shí)現(xiàn)C#數(shù)據(jù)加密”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么用對(duì)稱加密算法實(shí)現(xiàn)C#數(shù)據(jù)加密這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!