- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
密码学实验报告模板
密码学实验报告模板 (6000字)
院 系: 计算机科学学院 专 业:计算机科学与技术 年 级: 08级课程名称: 信息安全 班级 : 计科一大班
姓名学号:
指导教师: 孟博
2011年 11月 14 日
//RSA加密解密 package chp16;
import java.security.*;
import erfaces.*; import java.math.*; import java.io.*;
public class Password_Test { //用FileInputStream获取公钥 //用RSAPublicKey类中的方法获取公钥的参数(e,n) //用“BigInteger m = new BigInteger(ptext);”来获得明文整数 //执行计算 public static void main(String[] args) { try { new Password_Test(); Encryption_RSA(); } catch (Exception e) { e.printStackTrace(); } } public Password_Test() throws Exception {// 构造方法 创建公钥和私钥 KeyPairGenerator kpg = KeyPairGenerator.getInstance(quot;RSAquot;);//生成实现RSA算法的KeyPairGenerator对象。 kpg.initialize(1024);// 初始化确定密钥的大小 KeyPair kp = kpg.genKeyPair();// 生成密钥对
PublicKey pbkey = kp.getPublic();// 创建公钥 PrivateKey prkey = kp.getPrivate();// 创建私钥 // 保存公钥 FileOutputStream file1 = new FileOutputStream(quot;Skey_RSA_pub.datquot;); ObjectOutputStream ob1 = new ObjectOutputStream(file1);//创建ObjectOutputStream对象 ob1.writeObject(pbkey); //将指定的对象写入 ObjectOutputStream。 // 保存私钥 FileOutputStream file2 = new FileOutputStream(quot;Skey_RSA_priv.datquot;); ObjectOutputStream ob2 = new ObjectOutputStream(file2); ob2.writeObject(prkey); } public static void Encryption_RSA() throws Exception { System.out.println(quot;根据公钥生成密文:quot;+quot;\nquot;); String string = quot;I am a studentquot;; // 获取公钥及参数e,n FileInputStream f_in = new FileInputStream(quot;Skey_RSA_pub.datquot;); ObjectInputStream o_in = new ObjectInputStream(f_in); RSAPublicKey pbk = (RSAPublicKey) o_in.readObject(); BigInteger e = pbk.getPublicExponent();//返回此公钥的指数 BigInteger n = pbk.getModulus();//返回此公钥的模 System.out.println(quot;公钥的指数 e= quot; + e); System.out.println(quot;公钥的模 n= quot; + n); // 明文 bit byt
文档评论(0)