精选实习二数字签名与认证的实现资料Word格式.docx

上传人:b****1 文档编号:13224754 上传时间:2022-10-08 格式:DOCX 页数:15 大小:113.86KB
下载 相关 举报
精选实习二数字签名与认证的实现资料Word格式.docx_第1页
第1页 / 共15页
精选实习二数字签名与认证的实现资料Word格式.docx_第2页
第2页 / 共15页
精选实习二数字签名与认证的实现资料Word格式.docx_第3页
第3页 / 共15页
精选实习二数字签名与认证的实现资料Word格式.docx_第4页
第4页 / 共15页
精选实习二数字签名与认证的实现资料Word格式.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

精选实习二数字签名与认证的实现资料Word格式.docx

《精选实习二数字签名与认证的实现资料Word格式.docx》由会员分享,可在线阅读,更多相关《精选实习二数字签名与认证的实现资料Word格式.docx(15页珍藏版)》请在冰豆网上搜索。

精选实习二数字签名与认证的实现资料Word格式.docx

以本地两个目录模拟两个用户,实现消息M和签名的模拟分发;

实现过程:

 

A将信息M用自己的私钥加密后与M本身一起发送给B,B将签名用A的公钥解密,得出的信息与M对比,如果一致,说明消息就是A发的,因为只有A知道自己的私钥。

运行结果:

以MD5、SHA-1等哈希函数,实现消息M的摘要,实现M及摘要签名的模拟分发;

A对消息M用散列函数求出摘要,再用自己的私钥对摘要进行签名,将摘要和摘要的签名一起发送给B,B接受后用A的公钥解密摘要签名,将得出的摘要与发送的摘要对比,判断是否是A发送的。

MD5:

SHA-1:

实现M密文状态下的签名与模拟分发;

A对消息M用B的公钥进行加密,将密文用散列函数求出摘要,再用自己的私钥对摘要进行签名,将密文摘要和摘要的签名一起发送给B,B接受后用A的公钥解密摘要签名,将得出的摘要与发送的摘要对比,判断是否是A发送的,之后再使用自己的私钥解密得到的密文,最终得到明文消息M。

采用SSL,建立安全通信过程,实现Socket通信的签名分发;

将方案移植到某个web应用中,实现实用的签名分发。

4、实验总结

通过这次实验,对于数字签名的方式有了更多了解,认识到非对称密钥体系真的是一个很好的体系,既可以做签名,也可以进行加解密,功能很多。

附代码:

SKey_RSA.java

packagecn.test.key;

importjava.io.FileOutputStream;

importjava.io.ObjectOutputStream;

importjava.security.KeyPair;

importjava.security.KeyPairGenerator;

importjava.security.NoSuchAlgorithmException;

importjava.security.PrivateKey;

importjava.security.PublicKey;

publicclassSKey_RSA{

publicvoidkey_RSA()throwsException{

KeyPairGeneratorkpg=KeyPairGenerator.getInstance("

RSA"

);

kpg.initialize(1024);

KeyPairkp=kpg.genKeyPair();

PublicKeypbkey=kp.getPublic();

PrivateKeyprkey=kp.getPrivate();

FileOutputStreamf1=newFileOutputStream("

Skey_RSA_pub1.dat"

ObjectOutputStreamoo1=newObjectOutputStream(f1);

oo1.writeObject(pbkey);

FileOutputStreamf2=newFileOutputStream("

Skey_RSA_pri1.dat"

ObjectOutputStreamoo2=newObjectOutputStream(f2);

oo2.writeObject(prkey);

oo1.close();

oo2.close();

f1.close();

f2.close();

}

}

Rsa_Op.java

importjava.io.BufferedReader;

importjava.io.BufferedWriter;

importjava.io.FileInputStream;

importjava.io.FileNotFoundException;

importjava.io.InputStreamReader;

importjava.io.ObjectInputStream;

importjava.io.OutputStreamWriter;

importjava.math.BigInteger;

importjava.security.Key;

importjava.security.interfaces.RSAPrivateKey;

importjava.security.interfaces.RSAPublicKey;

publicclassRsa_Op{

intflag=0;

publicbyte[]enc_pub(Strings)throwsException{

byte[]b=s.getBytes("

UTF8"

FileInputStreamf=newFileInputStream("

ObjectInputStreamoi=newObjectInputStream(f);

RSAPublicKeypbk=(RSAPublicKey)oi.readObject();

oi.close();

BigIntegere=pbk.getPublicExponent();

BigIntegern=pbk.getModulus();

BigIntegerm=newBigInteger(b);

BigIntegerm1=newBigInteger("

0"

if((pareTo(m1))==-1){

m=m.negate();

flag=1;

}

BigIntegerc=m.modPow(e,n);

System.out.println("

M用公钥加密后的密文:

"

c="

+c);

byte[]re=c.toByteArray();

Stringcs=c.toString();

BufferedWriterbw=newBufferedWriter(newOutputStreamWriter(newFileOutputStream("

Enc_pub_RSA1.dat"

)));

bw.write(cs,0,cs.length());

bw.close();

returnre;

publicvoidenc_pri(Strings)throwsException{

RSAPrivateKeyprk=(RSAPrivateKey)oi.readObject();

BigIntegere=prk.getPrivateExponent();

BigIntegern=prk.getModulus();

签名前的M="

+m);

签名后的M="

//System.out.println("

将密钥加密后的密文c="

Enc_pri_RSA1.dat"

publicbyte[]dec_pri()throwsException{

BufferedReaderbr=newBufferedReader(newInputStreamReader(newFileInputStream("

Stringctext=br.readLine();

br.close();

BigIntegerc=newBigInteger(ctext);

BigIntegerd=prk.getPrivateExponent();

BigIntegerm=c.modPow(d,n);

if(flag==1){

flag=0;

将c解密后得:

);

m="

byte[]mt=m.toByteArray();

f.close();

returnmt;

publicbyte[]dec_pub()throwsException{

Sk

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1