仿真实验室实验报告.doc_第1页
仿真实验室实验报告.doc_第2页
仿真实验室实验报告.doc_第3页
仿真实验室实验报告.doc_第4页
仿真实验室实验报告.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

广 州 大 学实 验 报 告学 院 商学院 专业、班级 电子商务091 姓名、学号 庄泽帆 0901080028 课程名称 电子商务安全与管理 项目名称 数字签名实验 实验时间: 2011年 11 月 23 日 数字签名实验 实验报告开课实验室:仿真实验室2011年11月23日学院商学院年级、专业、班电商091姓名庄泽帆成绩课程名称电子商务安全与管理实验项目名 称数字签名实验指导教师签名一、实验目的电子商务和电子贸易的迅猛发展,使得因特网以及网络的安全问题越来越受到关注。本次实验将对电子商务常用的软件平台(java 2)平台下的加密及解密方法进行验证,通过本次实验具体要达到的实验目的如下:1. 数字签名的基本原理,理解数字签名的作用;2. 掌握数字摘要算法的基本原理3. 掌握java 2平台下的数字签名算法的实现;二、实验内容1. 熟悉java sdk中数字摘要算法api的用法;2. 计算一个文件的摘要;3. 对计算出的摘要进行数字签名;4. 对数字签名进行验证三、实验原理1. 数字签名的原理图2. 数字签名的处理过程 使用摘要函数对信息进行编码将发送文件加密产生128bit(或160bit)的数字摘要; 发送方用自己的专用密钥对摘要再加密,形成数字签名; 将原文和加密的摘要同时传给对方; 接收方用发送方的公共密钥对摘要解密,同时对收到的文件用摘要函数产生同一摘要; 将解密后的摘要和收到的文件在接受方重新加密产生的摘要相互对比,如果两者一致,则说明在传送过程中信息没有破坏和篡改。否则,则说明信息已经失去安全性和保密性。b) 基于rsa的数字签名算法3. java对数字签名算法的支持 keypairgenerator由于rsa算法是基于大素数分解数学难题的,因此该算法的主要问题是要产生一对大素数。keypairgenerator是一个用于产生rsa加密体制中的公钥和私钥对的引擎 . publickeypublickey类封装了rsa算法中的公钥(一个大素数)。 privatekey privatekey类封装了rsa算法中的私钥(一个大素数) messagedigest类该类提供了对各种摘要算法的支持 cipher类该类实现了对对称加密带来解密算法的支持。单步加密时使用cipher类中的dofinal()方法;多步加密时则要联合使用cipher中的update()方法和dofinal()方法。四、实验过程原始记录(数据、图表、计算等)五、实验结果及分析经过数字签名,加密前与加密后的摘要相一致,并且密文发生改变后摘要也相应改变了,实验成功。六、附录(自己实现的源代码)import java.io.*;import java.math.biginteger;import java.security.*;import java.security.keyfactory;import erfaces.*;import java.security.spec.*;import javax.crypto.*;public class rsa public static void main(string args) throws ioexception,nosuchalgorithmexception, invalidkeyspecexception,nosuchpaddingexception, invalidkeyexception,illegalblocksizeexception, badpaddingexception / 从c:/keypair.dat中读取n,e,dfileinputstream is = new fileinputstream(c:keypair.txt);bufferedinputstream bis = new bufferedinputstream(is);int rn = bis.read();byte arr_n = new bytern;bis.read(arr_n);rn = bis.read();byte arr_e = new bytern;bis.read(arr_e);rn = bis.read();byte arr_d = new bytern;bis.read(arr_d);/ 输出n,e,d与文件中的n,e,d进行对比biginteger n = new biginteger(arr_n);biginteger e = new biginteger(arr_e);biginteger d = new biginteger(arr_d);system.out.println(n: + n);system.out.println(e: + e);system.out.println(d: + d);biginteger modulus = new biginteger(arr_n);biginteger publicexponent = new biginteger(arr_e);biginteger privateexponent = new biginteger(arr_d);/ 生成公钥keyfactory keyfac = keyfactory.getinstance(rsa);rsapublickeyspec rsapublickeyspec = new rsapublickeyspec(modulus,publicexponent);rsapublickey pukey = (rsapublickey) keyfac.generatepublic(rsapublickeyspec);/ 生成私钥keyfac = keyfactory.getinstance(rsa);rsaprivatekeyspec rsaprivatekeyspec = new rsaprivatekeyspec(modulus,privateexponent);rsaprivatekey prkey = (rsaprivatekey) keyfac.generateprivate(rsaprivatekeyspec);/ create the ciphercipher rsacipher = cipher.getinstance(rsa);/ 读取摘要messagedigest alga = messagedigest.getinstance(sha);/ 添加要进行计算摘要的信息,注意了source.text里面是要进行加密的信息filewriter write = new filewriter(c:source.txt);write.write(ec在美国也才刚刚开始,之所以把ec列为一个划时代的东西,笔者认为,是因为internet的最终主要商业用途,就是电子商务。);write.close();fileinputstream i1 = new fileinputstream(c:source.txt);int len = i1.read();byte info = new bytelen;alga.update(info);fileoutputstream os = new fileoutputstream(c:digitaliginature.dat);dataoutputstream bos = new dataoutputstream(os);/ 得到加密前摘要byte jaimiqian = alga.digest();/ 用公钥对摘要进行加密,发现每次加密密文都会改变rsacipher.init(cipher.encrypt_mode, pukey);byte jaimihou = rsacipher.dofinal(jaimiqian);system.out.println(用公钥加密的密文: + tools.tohexstring(jaimihou);bos.writebytes(用公钥加密的密文: + jaimihou+n);/ 用私钥对密文进行解密rsacipher.init(cipher.decrypt_mode, prkey);byte jeimihou = rsacipher.dofinal(jaimihou);system.out.println(用公钥加密前摘要: + tools.tohexstring(jaimiqian);bos.writebytes(用公钥加密前摘要: + jaimiqian+n);system.out.println(用私钥解密后摘要: + tools.tohexstring(jeimihou);bos.writebytes(用私钥解密后摘要: + jeimihou+n);/ 用私钥对摘要进行加密,发现不管加密多少次,密文都不变rsacipher.init(cipher.encrypt_mode, prkey);byte jaimihou1 = rsacipher.dofinal(jaimiqian);system.out.println(用私钥加密的密文: + tools.tohexstring(jaimihou1);bos.writebytes(用私钥加密的密文: + jaimihou1+n);/ 用公钥对密文进行解密rsacipher.init(cipher.decrypt_mode, pukey);byte jeimihou1 = rsacipher.dofinal(jaimihou1);system.out.println(用私钥加密前摘要: + tools.tohexstring(jaimiqian);bos.writebytes(用私钥加密前摘要: + jaimiqian+n);system.out.println(用公钥解密后摘要: + tools.tohexstring(jeimihou1);bos.writebytes(用公钥解密后摘要: + jeimihou1+n);bos.close();filewriter writer=new filewriter(c:source.txt);writer.write(this is a text!);writer.close();int len1 = i1.read();byte info1 = new bytelen1;alga.update(info1);/ 得到加密前摘要byte jaimiqian2 = alga.digest();/ 用公钥对摘要进行加密,发现每次加密密文都会改变rsacipher.init(cipher.encrypt_mode, pukey);byte jaimihou2 = rsacipher.dofinal(jaimiqian2);system.out.println(文件篡改后用公钥加密的密文: + tools.tohexstring(jaimihou2);/ 用私钥对密文进行解密rsacipher.init(cipher.decrypt_mode, prkey);byte jeimihou2 = rsacipher.dofinal(jaimihou2);system.out.println(文件篡改后用公钥加密前摘要: + tools.tohexstring(jaimiqian2);system.out.println(文件篡改后用私钥解密后摘要: + tools.tohexstring(jeimihou2);/ 用私钥对摘要进行加密,发现不管加密多少次,密文都不变rsacipher.init(cipher.encrypt_mode, prkey);byte jaimihou3 = rsacipher.dofinal(jaimiqian2);system.out.println(文件篡改后用私钥加密的密文: + tools.tohexstring(jaimihou3);/ 用公钥对密文进行解密rsacipher.init(cipher.decrypt_mode, pukey);byte jeimihou3 = rsacipher.dofinal(jaimihou3);system.out.println(文件篡改后用私钥加密前摘要: + tools.tohexstring(jaimiqian2);system.out.println(文件篡改后用公钥解密后摘要: + tools.tohexstring(jeimihou3);class tools public static string tohexstring(byte block) stringbuffer buf = new stringbuffer();int len = block.length;for (int i = 0; i len; i+) byte2hex(blocki, buf);if (i 4);int low = (b & 0x0f);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论