信息安全实验报告信息安全概论课程设计报告书.docx
《信息安全实验报告信息安全概论课程设计报告书.docx》由会员分享,可在线阅读,更多相关《信息安全实验报告信息安全概论课程设计报告书.docx(16页珍藏版)》请在冰点文库上搜索。
信息安全实验报告信息安全概论课程设计报告书
郑州轻工业学院
课程设计报告
名称:
信息安全概论
指导教师:
吉星、程立辉
姓名:
符豪
学号:
541307030112
班级:
网络工程13-01
1.
目的
数据加密技术要求只有在指定的用户或网络下,才能解除密码而获得原来的数据,这就需要给数据发送方和接受方以一些特殊的信息用于加解密,这就是所谓的密钥。
其密钥的值是从大量的随机数中选取的。
按加密算法分为专用密钥和公开密钥两种。
数据加密技术是网络中最基本的安全技术,主要是通过对网络中传输的信息进行数据加密来保障其安全性,这是一种主动安全防御策略,用很小的代价即可为信息提供相当大的安全保护。
2.题目
使用C#编程语言,进行数据的加密与解密。
系统基本功能描述如下:
1、实现DES算法加密与解密功能。
2、实现TripleDES算法加密与解密功能。
3、实现MD5算法加密功能。
4、实现RC2算法加密与解密功能。
5、实现TripleDES算法加密与解密功能。
6、实现RSA算法加密与解密功能。
3.功能描述
使用该软件在相应的文本框中输入明文,然后点击加密就会立即转化成相应的密文,非常迅速和方便,而且操作简单加流畅,非常好用。
4.需求分析
加密软件发展很快,目前最常见的是透明加密,透明加密是一种根据要求在操作系统层自动地对写入存储介质的数据进行加密的技术。
透明加密软件作为一种新的数据保密手段,自2005年上市以来,得到许多软件公司特别是制造业软件公司和传统安全软件公司的热捧,也为广大需要对敏感数据进行保密的客户带来了希望。
加密软件上市以来,市场份额逐年上升,同时,经过几年的实践,客户对软件开发商提出了更多的要求。
与加密软件产品刚上市时前一两年各软件厂商各持一词不同,经过市场的几番磨炼,客户和厂商对透明加密软件有了更加统一的认识。
5.设计说明
传统的周边防御,比如防火墙、入侵检测和防病毒软件,已经不再能够解决很多今天的数据保护问题。
为了加强这些防御措施并且满足短期相关规范的要求,许多公司对于数据安全纷纷采取了执行多点产品的战术性措施。
这种片面的部署计划确实可以为他们的数据提供一点点额外的保护,但是在管理上花费昂贵并且操作困难,这种做法并不能为未来的发展提供一个清晰的框架。
加密是确保数据安全最重要的环节。
必须确保数据加密而不是仅仅依赖一个防护基础架构。
对数据进行加密可以让数据不论是在网络中活动、在数据库和电脑中静止或者在工作站中被使用的时候都能防患于未然。
6.源代码
主窗体:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm1:
Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidmd5ToolStripMenuItem_Click(objectsender,EventArgse)
{
md5md51=newmd5();
md51.Show();
}
privatevoiddES加密解密ToolStripMenuItem_Click(objectsender,EventArgse)
{
desdes1=newdes();
des1.Show();
}
privatevoidrSA加密解密ToolStripMenuItem_Click(objectsender,EventArgse)
{
rsarsa1=newrsa();
rsa1.Show();
}
privatevoid帮助ToolStripMenuItem_Click(objectsender,EventArgse)
{
helph=newhelp();
h.Show();
}
}
}
Cryptography类:
usingSystem;
usingSystem.Security.Cryptography;
usingSystem.IO;
usingSystem.Text;
usingSystem.Globalization;
usingSystem.Xml.Linq;
usingSystem.Collections.Generic;
namespaceWindowsFormsApplication1
{
classEncrypter
{
//DES默认密钥向量
privatestaticbyte[]DES_IV={0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF};
publicstaticstringEncryptByMD5(stringinput)
{
MD5md5Hasher=MD5.Create();
byte[]data=md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuildersBuilder=newStringBuilder();
for(inti=0;i{
sBuilder.Append(data[i].ToString("x2"));
}
returnsBuilder.ToString();
}
publicstaticstringEncryptByDES(stringinput,stringkey)
{
byte[]inputBytes=Encoding.UTF8.GetBytes(input);
byte[]keyBytes=ASCIIEncoding.UTF8.GetBytes(key);
byte[]encryptBytes=EncryptByDES(inputBytes,keyBytes,keyBytes);
using(DESdes=newDESCryptoServiceProvider())
{
using(MemoryStreamms=newMemoryStream())
{
using(CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write))
{
using(StreamWriterwriter=newStreamWriter(cs))
{
writer.Write(inputBytes);
}
}
}
}
stringresult=Convert.ToBase64String(encryptBytes);
returnresult;
}
publicstaticbyte[]EncryptByDES(byte[]inputBytes,byte[]key,byte[]IV)
{
DESdes=newDESCryptoServiceProvider();
des.Key=key;
des.IV=IV;
stringresult=string.Empty;
using(MemoryStreamms=newMemoryStream())
{
using(CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write))
{
cs.Write(inputBytes,0,inputBytes.Length);
}
returnms.ToArray();
}
}
publicstaticstringDecryptByDES(stringinput,stringkey)
{
byte[]inputBytes=Convert.FromBase64String(input);
byte[]keyBytes=ASCIIEncoding.UTF8.GetBytes(key);
byte[]resultBytes=DecryptByDES(inputBytes,keyBytes,keyBytes);
stringresult=Encoding.UTF8.GetString(resultBytes);
returnresult;
}
publicstaticbyte[]DecryptByDES(byte[]inputBytes,byte[]key,byte[]iv)
{
DESCryptoServiceProviderdes=newDESCryptoServiceProvider();
des.Key=key;
des.IV=iv;
using(MemoryStreamms=newMemoryStream(inputBytes))
{
using(CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Read))
{
using(StreamReaderreader=newStreamReader(cs))
{
stringresult=reader.ReadToEnd();
returnEncoding.UTF8.GetBytes(result);
}
}
}
}
publicstaticstringEncryptString(stringinput,stringsKey)
{
byte[]data=Encoding.UTF8.GetBytes(input);
using(DESCryptoServiceProviderdes=newDESCryptoServiceProvider())
{
des.Key=ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV=ASCIIEncoding.ASCII.GetBytes(sKey);
ICryptoTransformdesencrypt=des.CreateEncryptor();
byte[]result=desencrypt.TransformFinalBlock(data,0,data.Length);
returnBitConverter.ToString(result);
}
}
publicstaticstringDecryptString(stringinput,stringsKey)
{
string[]sInput=input.Split("-".ToCharArray());
byte[]data=newbyte[sInput.Length];
for(inti=0;i{
data[i]=byte.Parse(sInput[i],NumberStyles.HexNumber);
}
using(DESCryptoServiceProviderdes=newDESCryptoServiceProvider())
{
des.Key=ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV=ASCIIEncoding.ASCII.GetBytes(sKey);
ICryptoTransformdesencrypt=des.CreateDecryptor();
byte[]result=desencrypt.TransformFinalBlock(data,0,data.Length);
returnEncoding.UTF8.GetString(result);
}
}
publicstaticstringEncryptByRSA(stringplaintext,stringpublicKey)
{
UnicodeEncodingByteConverter=newUnicodeEncoding();
byte[]dataToEncrypt=ByteConverter.GetBytes(plaintext);
using(RSACryptoServiceProviderRSA=newRSACryptoServiceProvider())
{
RSA.FromXmlString(publicKey);
byte[]encryptedData=RSA.Encrypt(dataToEncrypt,false);
returnConvert.ToBase64String(encryptedData);
}
}
publicstaticstringDecryptByRSA(stringciphertext,stringprivateKey)
{
UnicodeEncodingbyteConverter=newUnicodeEncoding();
using(RSACryptoServiceProviderRSA=newRSACryptoServiceProvider())
{
RSA.FromXmlString(privateKey);
byte[]encryptedData=Convert.FromBase64String(ciphertext);
byte[]decryptedData=RSA.Decrypt(encryptedData,false);
returnbyteConverter.GetString(decryptedData);
}
}
publicstaticstringHashAndSignString(stringplaintext,stringprivateKey)
{
UnicodeEncodingByteConverter=newUnicodeEncoding();
byte[]dataToEncrypt=ByteConverter.GetBytes(plaintext);
using(RSACryptoServiceProviderRSAalg=newRSACryptoServiceProvider())
{
RSAalg.FromXmlString(privateKey);
//使用SHA1进行摘要算法,生成签名
byte[]encryptedData=RSAalg.SignData(dataToEncrypt,newSHA1CryptoServiceProvider());
returnConvert.ToBase64String(encryptedData);
}
}
publicstaticboolVerifySigned(stringplaintext,stringSignedData,stringpublicKey)
{
using(RSACryptoServiceProviderRSAalg=newRSACryptoServiceProvider())
{
RSAalg.FromXmlString(publicKey);
UnicodeEncodingByteConverter=newUnicodeEncoding();
byte[]dataToVerifyBytes=ByteConverter.GetBytes(plaintext);
byte[]signedDataBytes=Convert.FromBase64String(SignedData);
returnRSAalg.VerifyData(dataToVerifyBytes,newSHA1CryptoServiceProvider(),signedDataBytes);
}
}
publicstaticKeyValuePairCreateRSAKey()
{
RSACryptoServiceProviderRSA=newRSACryptoServiceProvider();
stringprivateKey=RSA.ToXmlString(true);
stringpublicKey=RSA.ToXmlString(false);
returnnewKeyValuePair(publicKey,privateKey);
}
publicstaticbyte[]GetBytes(stringinput)
{
string[]sInput=input.Split("-".ToCharArray());
byte[]inputBytes=newbyte[sInput.Length];
for(inti=0;i{
inputBytes[i]=byte.Parse(sInput[i],NumberStyles.HexNumber);
}
returninputBytes;
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Security.Cryptography;
namespaceWindowsFormsApplication1
{
publicpartialclassmd5:
Form
{
publicmd5()
{
InitializeComponent();
}
privatevoidlabel1_Click(objectsender,EventArgse)
{
}
privatevoidmd5_Load(objectsender,EventArgse)
{
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
if(textBox1.Text!
="")
{
textBox2.Text=Encrypter.EncryptByMD5(textBox1.Text);
}
else
MessageBox.Show("不能为空");
}
}
}
7.测试报告
8.心得体会
通过本次实验,我学习到了数据在互联网中的传输并不是绝对的安全。
由于这样或那样的原因使得在传输的过程中都要使用一些加密的手段,以提高数据的安全性。
本次实验中,我们举要验证的在网络中下载的文件的正确性(是不是正版是不是有恶意插件)通过MD5校验工具对其进行校验和官网上的比较结果!
设计也是一项具体的设计思路,通过对字符的移动而实现对信息的加密。
这是非常有效的一项方法,对自己的私密信息的保护守法!
只不过有待改进的是只有对英文的实用性,对于汉字的加密有待商榷中!
最后感谢老师的辛苦教学。