Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 for one protocol's verification
lping9188



发贴: 0
积分: 0
于 2003-03-11 19:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Hi,
I want to implement one protocol, which used the verifciation: Be given a multiplicative of a random number and a signed data, then decrypt the multiplicative by using public key, the result should be equal to a multiplicative of the hash data and the encrypted data of the reandom number by public key.
I made such a programme, if I replace hash value by another byte[] data,it success, but when use hash value, it always failed.

MessageDigest md= MessageDigest.getInstance("SHA-1");
md.update("data".getBytes());
byte[] hash= md.digest();

/* if I use that one replace the hash value, it success;
byte[] hash="MessageDigest md= MessageDigest.getInstance;".getBytes();*/

Cipher c = Cipher.getInstance("RSA","BC");
c.init(Cipher.ENCRYPT_MODE,pri1);
byte[] encrypted = c.doFinal(hash);

BigInteger encryptedbig=new BigInteger(encrypted);

byte[] r="6".getBytes(); //just take as a random number;

BigInteger rbig=new BigInteger(r);

BigInteger Xb=rbig.multiply(encryptedbig);

BigInteger XB=Xb.modPow(exp1,n1);

BigInteger XBm=XB.mod(n1);
RSAKeyGenParameterSpec para=new RSAKeyGenParameterSpec(2048,exp1);

KeyPairGenerator kg2 = KeyPairGenerator.getInstance("RSA","BC");
kg2.initialize(para);
KeyPair kp2 = kg2.generateKeyPair();

RSAPrivateCrtKey pri2 = ( RSAPrivateCrtKey) kp2.getPrivate();

RSAPublicKey pub2 = ( RSAPublicKey) kp2.getPublic();

BigInteger n2=pub2.getModulus();

BigInteger n3=n1.multiply(n2);
BigInteger Yb=rbig.modPow(exp1,n3);
BigInteger Ybb=rbig.modPow(exp1,n1);

BigInteger Yb1=Yb.mod(n1);

BigInteger hashbig=new BigInteger(hash);

BigInteger Ybbig=hashbig.multiply(Yb1);

BigInteger Ybbb=Ybbig.mod(n1);

if(XBm.equals(Ybbb))
{
System.out.println("Success");
}
else
{

System.out.println("Failed");
}




话题树型展开
人气 标题 作者 字数 发贴时间
6542 for one protocol's verification lping9188 1792 2003-03-11 19:43
5359 Re:for one protocol's verification floater 90 2003-03-19 03:13

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923