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

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 关于JCE的使用,这个错误怎么回事?
feiggle





发贴: 70
积分: 20
于 2003-04-14 15:52 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
看到论坛上一篇文章,照着作了,如下代码:

// GenerateKey.java
import java.security.SecureRandom;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class GenerateKey {
static public void main(String args[]) throws Exception {
//String keyFilename = args[0];
String keyFilename="c:\\key";
String algorithm = "DES";
// 生成密匙
SecureRandom sr = new SecureRandom();
KeyGenerator kg = KeyGenerator.getInstance(algorithm);
kg.init(sr);
SecretKey key = kg.generateKey();
// 把密匙数据保存到文件
Util.writeFile(keyFilename, key.getEncoded());
}
}

代码好像没错,运行时,出现如下错误,那位大侠遇到过?请指教!
jre为1.4.1_02,用到的jar都加到classpath中了
错误信息:

java.lang.NoClassDefFoundError: javax/crypto/KeyGeneratorSpi
  at java.lang.ClassLoader.defineClass0(Native Method)
  at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
  at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
  at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
  at javax.crypto.SunJCE_b.c(DashoA6275)
  at javax.crypto.SunJCE_b.a(DashoA6275)
  at javax.crypto.KeyGenerator.getInstance(DashoA6275)
  at avicit.encrypted.GenerateKey.main(GenerateKey.java:17)


feiggle edited on 2003-04-15 16:41


作者 Re:关于JCE的使用,这个错误怎么回事?(is Sun a bug? ) [Re:feiggle]
menzy



版主


发贴: 754
积分: 113
于 2003-04-15 13:13 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
看情况是没有发现 实现 KeyGenerator的接口类,可能是没有任何类提供相应的服务,也就是说,应当AddServiceProvider(new TheImplementorClass())


作者 Re:关于JCE的使用,这个错误怎么回事?(is Sun a bug? ) [Re:feiggle]
feiggle





发贴: 70
积分: 20
于 2003-04-15 15:03 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
i try it,thanks


作者 Re:关于JCE的使用,这个错误怎么回事? [Re:feiggle]
iwtg





发贴: 21
积分: 0
于 2003-05-29 09:09 user profilesend a private message to usersend email to iwtgsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以运行的,我没有用你的写文件,而是直接输出来,正常



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