谈谈数据加密的处理要点

上传人:re****.1 文档编号:487456500 上传时间:2023-07-17 格式:DOC 页数:39 大小:333.50KB
返回 下载 相关 举报
谈谈数据加密的处理要点_第1页
第1页 / 共39页
谈谈数据加密的处理要点_第2页
第2页 / 共39页
谈谈数据加密的处理要点_第3页
第3页 / 共39页
谈谈数据加密的处理要点_第4页
第4页 / 共39页
谈谈数据加密的处理要点_第5页
第5页 / 共39页
点击查看更多>>
资源描述

《谈谈数据加密的处理要点》由会员分享,可在线阅读,更多相关《谈谈数据加密的处理要点(39页珍藏版)》请在金锄头文库上搜索。

1、谈谈数据加密的处理-提供各种算法处理数据的加密重要性大家皆知,很多情况下需要对数据进行加密处理,但各种重要数据的加密 要求不一样,有些需要时可逆的,有些是不要求可逆的,可逆的一般称之为对称加密算法, 不可逆的一般可以成为非对称加密算法。如登录密码,一般较好的方式是采用不可逆的加密 算法,如MD5、SHA256、哈希数值等,当然也有的采用可逆的强度好一些的加密方式,在 选择加密键值的时候,变化一下也算是比较不错的选择。另外一些为了掩人耳目或者不让别 人直接可以查看到,就采用其他的加密算法,如DES加密算法、AES的RijndaelManaged加密算法,或者也可以采用Base64加密,甚至我看到

2、一个很变态的方式,就是用 MD5加密的头,内容则采用 Base64的方式加密,一般不知道内情的还真的不好处理。在吉日走火入魔失眠夜浅谈管理软件信息安全,用户名、密码的加密解密【附 C#配套加 密解密源码】的文章中也对加密做了一些介绍和分析,并贴出了MD5、DES的加密方式代码,吉日的文章图文并茂、哲理及诙谐例子并存,本文有感而发,做一些补充,希望园子 同行共通过切磋,交流心得。加密字符串的方式有很多,也都可以通过这样的加密文件内容,不过较好的方式可能是采用DES及AES两种方式来加密文件了, 下面贴出的代码中包含了加解密文件的算法。下面具体贴出本人收藏的各种加密算法代码。1、DES加密字符串及

3、文件等如果想可逆的算法,这种方式一般不错,只要结合动态密钥,就可以做出强度比较高的加密 应用了。#region DES对称加密解密public const stri ng DEFAULT_ENCRYPT_KEY = 12345678;/ /使用默认加密/ / vparam n ame=strText/ public static string DesEncrypt(string strText)tryreturn DesE ncrypt(strText, DEFAULT_ENCRYPT_KEY);catchreturn ;/ /使用默认解密/ / vparam n ame=strText/ v

4、retur nspublic static string DesDecrypt(string strText)tryreturn DesDecrypt(strText, DEFAULT_ENCRYPT_KEY);catchreturn ;/ / En crypt the stri ngIII Atte nti on:key must be 8 bits/ / vparam n ame=strTextstri ng/ vparam n ame=strE ncrKeykey/ vretur nspublic static string DesEncrypt(string strText, stri

5、ng strEncrKey)byte byKey = null;byte IV = 0x12, 0x34, 0x56, 0x78, 0x90, OxAB, OxCD, 0xEF ;byKey = Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8);DESCryptoServiceProvider des = new DESCryptoServiceProvider();byte in putByteArray = En codi ng.UTF8.GetBytes(strText);MemoryStream ms = new MemoryStrea

6、m();CryptoStream cs = new CryptoStream(ms, des.CreateE ncryptor(byKey, IV),CryptoStreamMode.Write);cs.Write(i nputByteArray, 0, in putByteArray.Le ngth);cs.FlushFi nalBlock();return Con vert.ToBase64Stri ng(ms.ToArray();/ / Decrypt stri ng/ Attention:key must be 8 bits/ / vparam n ame=strTextDecrypt

7、 stri ngv/param/ vparam n ame=sDecrKeykey/ vretur nsoutput stri ngv/retur nspublic static stri ng DesDecrypt(stri ng strText, stri ng sDecrKey)byte byKey = null;byte IV = 0x12, 0x34, 0x56, 0x78, 0x90, OxAB, OxCD, OxEF ;byte in putByteArray = new BytestrText.Le ngth;byKey = Encoding.UTF8.GetBytes(sDe

8、crKey.Substring(0, 8);DESCryptoServiceProvider des = new DESCryptoServiceProvider();in putByteArray = Con vert.FromBase64Stri ng(strText);MemoryStream ms = new MemoryStream();CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV),CryptoStreamMode.Write);cs.Write(i nputByteArray, 0, in

9、 putByteArray.Le ngth);cs.FlushFi nalBlock();En codi ng en codi ng = new UTF8E ncodi ng();retur n en cod in g.GetStri ng(ms.ToArray();/ / En crypt files/ Attention:key must be 8 bits/ / E ncrypt file path/ output file/ keypublic static void DesEncrypt(string m_InFilePath, string m_OutFilePath, strin

10、g strEncrKey)byte byKey = null;byte IV = 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF ;byKey = Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8);FileStream fin = new FileStream (mn FilePath, FileMode.Ope n, FileAccess.Read);FileStream fout = new FileStream(m_OutFilePath, FileMode.Ope nOrCreate,Fil

11、eAccess.Write);fout.SetLe ngth(O);/Create variables to help with read and write.byte bin = new byte100; /This is in termediate storage for the en crypti on.long rdlen = 0; /This is the total number of bytes written.long totle n = fin .Le ngth; /This is the total le ngth of the in put file.int len; /

12、This is the number of bytes to be written at a time.DES des = new DESCryptoServiceProvider();CryptoStream en cStream = new CryptoStream(fout, des.CreateE ncryptor(byKey,IV), CryptoStreamMode.Write);/Read from the in put file, the n en crypt and write to the output file.while (rdle n totle n)len = fi

13、n .Read(bi n, 0, 100);en cStream.Write(b in, 0, le n);rdle n = rdle n + len;en cStream.Close();fout.Close();fin .Close();/ / Decrypt files/ Attention:key must be 8 bits/ / Decrypt filepath/ output filepath/ keypublic static void DesDecrypt(string m_InFilePath, string m_OutFilePath, string sDecrKey) byte byKey = null;byte IV = 0x12, 0x34, 0x56, 0x78, 0x90, OxAB, OxCD, OxEF ;byKey = En codi ng.UTF8.GetBytes(sDecrKey.Substri ng(0, 8);FileStream fin = new FileStream (mn FilePath, FileMode.Ope n, FileAccess.Read);FileStr

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号