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

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求救~程序生成密钥对出错~
坏到刚刚好





发贴: 2
积分: 0
于 2005-05-16 19:24 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
程序如下,执行没有错误,可是就是没有生成密钥队对~希望高手帮忙~

import java.io.*;
import java.security.*;
public class GenerateKeyPair{
public static void main(String[] args){
boolean bHelp=false;
FileOutputStream fileOut;

File filename=new File("xr.txt");

byte[] pubKey;
byte[] privKey;

if(args.length!=1)
{
System.out.println("Usage:GenerateKeyPair <keyname>");
System.out.println("Option:");
System.out.println("<keyname>:The key name that using to generate filename.");
System.exit(0);
}
try{
System.out.println("Generating a key pair.....");
KeyPairGenerator KeyGen=KeyPairGenerator.getInstance("DSA");
KeyGen.initialize(1024,new SecureRandom());
KeyPair pair=KeyGen.generateKeyPair();
PublicKey pub=pair.getPublic();
PrivateKey priv=pair.getPrivate();
pubKey=pub.getEncoded();
privKey= priv.getEncoded();
fileOut=new FileOutputStream("PublicKey_"+args[0]);
fileOut.write(pubKey);
fileOut.close();
fileOut=new FileOutputStream("privateKey_"+args[0]);
fileOut.write(privKey);
fileOut.close();
System.out.println("OK!");
}catch(Exception e){
}
}

}




作者 Re:求救~程序生成密钥对出错~ [Re:坏到刚刚好]
menzy



版主


发贴: 754
积分: 113
于 2005-05-17 16:44 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
你怎么知道执行没有错?你根本就没有把catch的异常打印出来!


作者 Re:求救~程序生成密钥对出错~ [Re:坏到刚刚好]
坏到刚刚好





发贴: 2
积分: 0
于 2005-05-17 19:46 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
不好意思~我是菜鸟~不懂呀~
程序是可以执行的~可就是没有生成密钥对~
程序执行结果是:
Usage:GenerateKeyPair <keyname>;
Option:
keyname>:The key name that using to generate filename.

就这个结果~我不懂~



作者 Re:求救~程序生成密钥对出错~ [Re:坏到刚刚好]
menzy



版主


发贴: 754
积分: 113
于 2005-05-20 10:38 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
System.out.println("Usage:GenerateKeyPair <keyname>");
System.out.println("Option:");
System.out.println("<keyname>:The key name that using to generate filename.");
System.exit(0);

你的用法不对, 仔细看看usage!!!




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