- 浏览: 236818 次
- 性别:
- 来自: 天津
文章分类
最新评论
-
yulanlian:
...
实现在删除数据后,自增列的值连续 -
RonQi:
楼主写的很好,支持原创!
Google Protocol Buffers
using System; using System.Text; using System.Security; using System.Security.Cryptography; using System.IO; namespace EncryptClasses { /// <summary> /// 此处定义的是DES加密,为了便于今后的管理和维护 /// 请不要随便改动密码,或者改变了密码后请一定要 /// 牢记先前的密码,否则将会照成不可预料的损失 /// </summary> public class DESEncrypt { #region "member fields" private string iv="12345678"; private string key="12345678"; private Encoding encoding=new UnicodeEncoding(); private DES des; #endregion /// <summary> /// 构造函数 /// </summary> public DESEncrypt() { des=new DESCryptoServiceProvider(); } #region "propertys" /// <summary> /// 设置加密密钥 /// </summary> public string EncryptKey { get{return this.key;} set { this.key=value; } } /// <summary> /// 要加密字符的编码模式 /// </summary> public Encoding EncodingMode { get{return this.encoding;} set{this.encoding=value;} } #endregion #region "methods" /// <summary> /// 加密字符串并返回加密后的结果 /// </summary> /// <param name="str"></param> /// <returns></returns> public string EncryptString(string str) { byte[] ivb=Encoding.ASCII.GetBytes(this.iv); byte[] keyb=Encoding.ASCII.GetBytes(this.EncryptKey);//得到加密密钥 byte[] toEncrypt=this.EncodingMode.GetBytes(str);//得到要加密的内容 byte[] encrypted; ICryptoTransform encryptor=des.CreateEncryptor(keyb,ivb); MemoryStream msEncrypt=new MemoryStream(); CryptoStream csEncrypt=new CryptoStream(msEncrypt,encryptor,CryptoStreamMode.Write); csEncrypt.Write(toEncrypt,0,toEncrypt.Length); csEncrypt.FlushFinalBlock(); encrypted=msEncrypt.ToArray(); csEncrypt.Close(); msEncrypt.Close(); return this.EncodingMode.GetString(encrypted); } /// <summary> /// 加密指定的文件,如果成功返回True,否则false /// </summary> /// <param name="filePath">要加密的文件路径</param> /// <param name="outPath">加密后的文件输出路径</param> public void EncryptFile(string filePath,string outPath) { bool isExist=File.Exists(filePath); if(isExist)//如果存在 { byte[] ivb=Encoding.ASCII.GetBytes(this.iv); byte[] keyb=Encoding.ASCII.GetBytes(this.EncryptKey); //得到要加密文件的字节流 FileStream fin=new FileStream(filePath,FileMode.Open,FileAccess.Read); StreamReader reader=new StreamReader(fin,this.EncodingMode); string dataStr=reader.ReadToEnd(); byte[] toEncrypt=this.EncodingMode.GetBytes(dataStr); fin.Close(); FileStream fout=new FileStream(outPath,FileMode.Create,FileAccess.Write); ICryptoTransform encryptor=des.CreateEncryptor(keyb,ivb); CryptoStream csEncrypt=new CryptoStream(fout,encryptor,CryptoStreamMode.Write); try { //加密得到的文件字节流 csEncrypt.Write(toEncrypt,0,toEncrypt.Length); csEncrypt.FlushFinalBlock(); } catch(Exception err) { throw new ApplicationException(err.Message); } finally { try { fout.Close(); csEncrypt.Close(); } catch { ; } } } else { throw new FileNotFoundException("没有找到指定的文件"); } } /// <summary> /// 文件加密函数的重载版本,如果不指定输出路径, /// 那么原来的文件将被加密后的文件覆盖 /// </summary> /// <param name="filePath"></param> public void EncryptFile(string filePath) { this.EncryptFile(filePath,filePath); } /// <summary> /// 解密给定的字符串 /// </summary> /// <param name="str">要解密的字符</param> /// <returns></returns> public string DecryptString(string str) { byte[] ivb=Encoding.ASCII.GetBytes(this.iv); byte[] keyb=Encoding.ASCII.GetBytes(this.EncryptKey); byte[] toDecrypt=this.EncodingMode.GetBytes(str); byte[] deCrypted=new byte[toDecrypt.Length]; ICryptoTransform deCryptor=des.CreateDecryptor(keyb,ivb); MemoryStream msDecrypt=new MemoryStream(toDecrypt); CryptoStream csDecrypt=new CryptoStream(msDecrypt,deCryptor,CryptoStreamMode.Read); try { csDecrypt.Read(deCrypted,0,deCrypted.Length); } catch(Exception err) { throw new ApplicationException(err.Message); } finally { try { msDecrypt.Close(); csDecrypt.Close(); } catch{;} } return this.EncodingMode.GetString(deCrypted); } /// <summary> /// 解密指定的文件 /// </summary> /// <param name="filePath">要解密的文件路径</param> /// <param name="outPath">解密后的文件输出路径</param> public void DecryptFile(string filePath,string outPath) { bool isExist=File.Exists(filePath); if(isExist)//如果存在 { byte[] ivb=Encoding.ASCII.GetBytes(this.iv); byte[] keyb=Encoding.ASCII.GetBytes(this.EncryptKey); FileInfo file=new FileInfo(filePath); byte[] deCrypted=new byte[file.Length]; //得到要解密文件的字节流 FileStream fin=new FileStream(filePath,FileMode.Open,FileAccess.Read); //解密文件 try { ICryptoTransform decryptor=des.CreateDecryptor(keyb,ivb); CryptoStream csDecrypt=new CryptoStream(fin,decryptor,CryptoStreamMode.Read); csDecrypt.Read(deCrypted,0,deCrypted.Length); } catch(Exception err) { throw new ApplicationException(err.Message); } finally { try { fin.Close(); } catch{;} } FileStream fout=new FileStream(outPath,FileMode.Create,FileAccess.Write); fout.Write(deCrypted,0,deCrypted.Length); fout.Close(); } else { throw new FileNotFoundException("指定的解密文件没有找到"); } } /// <summary> /// 解密文件的重载版本,如果没有给出解密后文件的输出路径, /// 则解密后的文件将覆盖先前的文件 /// </summary> /// <param name="filePath"></param> public void DecryptFile(string filePath) { this.DecryptFile(filePath,filePath); } #endregion } /// <summary> /// MD5加密类,注意经MD5加密过的信息是不能转换回原始数据的 /// ,请不要在用户敏感的信息中使用此加密技术,比如用户的密码, /// 请尽量使用对称加密 /// </summary> public class MD5Encrypt { private MD5 md5; public MD5Encrypt() { md5=new MD5CryptoServiceProvider(); } /// <summary> /// 从字符串中获取散列值 /// </summary> /// <param name="str">要计算散列值的字符串</param> /// <returns></returns> public string GetMD5FromString(string str) { byte[] toCompute=Encoding.Unicode.GetBytes(str); byte[] hashed=md5.ComputeHash(toCompute,0,toCompute.Length); return Encoding.ASCII.GetString(hashed); } /// <summary> /// 根据文件来计算散列值 /// </summary> /// <param name="filePath">要计算散列值的文件路径</param> /// <returns></returns> public string GetMD5FromFile(string filePath) { bool isExist=File.Exists(filePath); if(isExist)//如果文件存在 { FileStream stream=new FileStream(filePath,FileMode.Open,FileAccess.Read); StreamReader reader=new StreamReader(stream,Encoding.Unicode); string str=reader.ReadToEnd(); byte[] toHash=Encoding.Unicode.GetBytes(str); byte[] hashed=md5.ComputeHash(toHash,0,toHash.Length); stream.Close(); return Encoding.ASCII.GetString(hashed); } else//文件不存在 { throw new FileNotFoundException("指定的文件没有找到"); } } } /// <summary> /// 用于数字签名的hash类 /// </summary> public class MACTripleDESEncrypt { private MACTripleDES mact; private string __key="ksn168ch"; private byte[] __data=null; public MACTripleDESEncrypt() { mact=new MACTripleDES(); } /// <summary> /// 获取或设置用于数字签名的密钥 /// </summary> public string Key { get{return this.__key;} set { int keyLength=value.Length; int[] keyAllowLengths=new int[]{8,16,24}; bool isRight=false; foreach(int i in keyAllowLengths) { if(keyLength==keyAllowLengths[i]) { isRight=true; break; } } if(!isRight) throw new ApplicationException("用于数字签名的密钥长度必须是8,16,24值之一"); else this.__key=value; } } /// <summary> /// 获取或设置用于数字签名的用户数据 /// </summary> public byte[] Data { get{return this.__data;} set{this.__data=value;} } /// <summary> /// 得到签名后的hash值 /// </summary> /// <returns></returns> public string GetHashValue() { if(this.Data==null) throw new NotSetSpecialPropertyException("没有设置要进行数字签名的用户"+ "数据(property:Data)"); byte[] key=Encoding.ASCII.GetBytes(this.Key); this.mact.Key=key; byte[] hash_b=this.mact.ComputeHash(this.mact.ComputeHash(this.Data)); return Encoding.ASCII.GetString(hash_b); } } }
发表评论
-
win7和VS2010下配置OpenGL的方法
2011-01-15 23:45 6369刚装了win7和VS2010。看了下配置OpenGL的方法和以 ... -
用好ASP.NET 2.0的URL映射
2010-12-06 08:31 715简介: URL映射是ASP.NET 2.0中提供的 ... -
加密web.config中数据参数的信息
2010-12-06 08:17 779我们都知道web.config可以保存连接字符串, ... -
主题:ASP.NET加上水印
2010-12-02 19:56 775为我们发布的图片加上一个水印,也是我们经常要做的事情,那怎 ... -
asp.net 2.0 读写配置文件
2010-12-01 11:13 1054下面我给出一个简单的例子说明如何使用WebConf ... -
ASP.NET配置文件的读、写操作
2010-12-01 11:03 1271虽然web.config文件是一个XML文件,但是由于权限的原 ... -
使用aspx实现发送email
2010-11-28 22:08 695源代码如下:using System; using Syst ... -
未能加载文件或程序集system.web.extensions解决方法
2010-11-27 09:40 1592未能加载文件或程序集system.web.extensions ... -
asp.net根据域名查ip C#版
2010-10-31 17:04 975网上有类似的教程,但是是asp.net 1.1的版本,这是本人 ... -
如何构造一个C#语言的爬虫程序
2010-10-31 17:03 833C#特别适合于构造蜘蛛 ... -
C#代码与javaScript函数的相互调用
2010-10-31 16:55 1086C#代码与javaScript函数的相互调用 我们通过问答 ... -
C#操作XML的类:xmlHelper例子
2010-10-31 16:31 4413首先,看下这个XmlHelper类库的结构,如下图: 然后, ... -
C#知识点总结_委托篇
2010-10-30 18:10 585C#知识点总结1——委托篇 1.委托概念: 当要把方法传 ... -
调用Windows API
2010-10-30 18:04 961在.Net Framework SDK文档中 ... -
C#中正确的调用API函数
2010-10-30 18:02 950在C#中经常需要调用一些API函数,那么怎样才能正确的调用AP ... -
用C#和本地Windows API操纵系统菜单
2010-10-30 18:00 1470一、前言 .NET框架是Windows应用领域中一个非常新 ... -
.NET(C#)连接各类数据库代码-集锦
2010-09-05 07:59 12551.C#连接连接Access using System.Da ... -
C#调用rar.exe解压一个rar文件到系统的临时目录
2010-08-31 00:04 1842//取得系统临时目录 string sysTempDir = ... -
C#实现winform软件开机自动启动并最小化到系统托盘
2010-08-31 00:01 4342一、开机自动启动: 拖一个CheckBox 1、软件启动时 ... -
C#里面比较时间大小三种方法收藏
2010-08-30 23:56 12321.比较时间大小的实验 string st1 ...
相关推荐
已知最可靠+方便的asp.net加密保护产品!选择web虎的10个理由 1.已有近600家各类b/s软件源代码加密防盗版成功案例,2+年稳定运行、实用检验,其中包括黑龙江卫生厅、宁夏卫生厅等 2.完全免费,并可提供远程协助 3....
第二部分(6~17章)则对.NET中的关键知识点进行了深入剖析,如程序集、流和序列化、加密与解密、网络编程、.NET Remoting、在.NET中操作XML、.NET应用程序配置、基于角色的安全性、反射、多线程、对象生存期与垃圾...
我们还将使用加密技术来保护用户的敏感信息,如密码和支付信息。 缓存管理:为了提高应用程序的性能,我们将使用ASP.NET提供的缓存机制来缓存常用的数据和页面。这将减少对数据库和服务器的访问次数,提高应用程序的...
主要在讨论常见WEB应用安全防护技术的基础上,重点研究Web.config配置文件的加密与解密、图文验证技术、防盗链技术
ASP.NET 4.0技术概述、ASP.NET程序的编译模型、将ASP.NET程序开发服务器Port固定的技巧、C# 4.0语言....NET 网页授权、Profile配置文件应用、加密Profile配置文件、Web组件框架和Web组件的个性化数据的管理等方面的技术...
本书详细介绍了在现有MFC应用程序中综合运用.NET框架的技术。全书共分11章,内容包括正则表达式、文件I/O和注册表、数据加密、XML和DOM、ADO .NET数据库、远程处理、事件日志等。为了让读者透彻理解如何运用.NET框架...
21.2.2 申请服务器证书 21.2.3 安装服务器证书 21.3 在ASP.NET页面中使用SSL 21.4 使用.NET加密类 21.4.1 使用散列算法 21.4.2 使用对称加密算法 21.4.3 使用不对称加密 21.5 小结 ...
.net加密,提供安全性的代码,更有利于大家讨论此项技术
9.2.NET对加密和解密的支持 9.2.1散列运算 9.2.2对称加密和解密 9.2.3非对称加密 9.3本章小结 第10章网络编程 10.1网络编程基本概念 10.1.1 面向连接的传输协议——TCP 10.1.2 即时通信程序的三种模式 10.2...
本书详细介绍了在现有MFC应用程序中综合运用.NET框架的技术。全书共分11章,内容包括正则表达式、文件I/O和注册表、数据加密、XML和DOM、ADO .NET数据库、远程处理、事件日志等。为了让读者透彻理解如何运用.NET框架...
将 ASP.NET 2.0 应用程序服务配置为使用 SQL Server 2000 或 SQL Server 2005 ASP.NET 2.0 中的数据源控件 使用 ASP.NET 2.0 ObjectDataSource 控件 ASP.NET 2.0 的内部变化 使用SQL Cache Dependency 代替 ...
我们还将使用加密技术来保护用户的敏感信息,如密码和支付信息。 缓存管理:为了提高应用程序的性能,我们将使用ASP.NET提供的缓存机制来缓存常用的数据和页面。这将减少对数据库和服务器的访问次数,提高应用程序的...
基于C#语言的ASP.NET 2.0动态网站开发基础教程,课程列表如下: ASP.NET 2.0动态网站开发基础教程...ASP.NET 2.0动态网站开发基础教程(C#) 第11章 提高ASP.NET应用程序的安全性 身份验证和授权 SSL加密(共9页).ppt
强大的软件防盗版工具:.NET Reactor ...保护.NET应用程序和.NET库文件 CIL代码与本地代码替换执行额外的保护层,包括混淆,程序集合并,在试用版中加入多种功能锁, 从而让用户更加愿意购买正版。
ASP.NET编程技术与交互式网页设计 asp.net亲密接触_带源码 C#学习 01_类.htm.txt 02_构造函数的执行序列.htm.txt 03_抽象类和接口.htm.txt 04_结构类型.htm.txt 05_类成员的定义.htm.txt 06_类成员的其他...
ASP的最新版本ASP.NET是Microsoft用于建立动态的数据库驱动网站的技术。内容包括:ASP.NET Web表单的使用,高级ASP.NET页面的开发,ADO.NET的使用,ASP.NET应用程序的使用, ASP.NET应用程序的保护,ASP.NET Web服务...
表单知识、.NET运行机制、Visual Studio 2008技巧、ASP.NET服务器控件的使用、SQL注入防范、单元测试、三层架构、报表、数据加密/解密、GDI+、ADO.NET、分布式开发、AJAX开发及静态页面生成技术、高性能ASP.NET应用...
我们还将使用加密技术来保护用户的敏感信息,如密码和支付信息。 缓存管理:为了提高应用程序的性能,我们将使用ASP.NET提供的缓存机制来缓存常用的数据和页面。这将减少对数据库和服务器的访问次数,提高应用程序的...
• 加密技术、密钥和证书 • 词汇表 返回页首 系统要求 本指南将帮助您使用 .NET Framework 针对 Windows 2000 设计和构建安全的 ASP.NET 应用程序。我们以 .NET Framework 版本 1 (service pack 2) 为目标,虽然...
如果你想设置发送邮箱可以...学习和讨论有关asp.net mvc ,Ajax ,jquery ,html/css, xml,sqlserver ,wpf,IIS以及服务器的搭建和安全性相关技术的交流和学习。 开发环境为Visual Studio 2010,数据库为SQL Server 2008R2