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

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 关于BouncyCastle 这个问题
317991923





发贴: 1
积分: 0
于 2004-10-25 22:01 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
刚装完Bouncy castle 的JCE 运行一个程序,就出现问题,而且问题好像都一样,我估计是不是已经安装了SUN 提供的JCE 地缘故呀,望各位兄台多多指教。
import java.security.*;
import java.security.interfaces.*;
import javax.crypto.*;
import java.io.*;

public class RSAEnAndDecrypt {
public RSAEnAndDecrypt() {
}

public static byte[] crypt(Cipher cipher, byte[] bytes) throws Exception {

CipherInputStream ciIn = new CipherInputStream(new ByteArrayInputStream(bytes), cipher);
ByteArrayOutputStream baOut = new ByteArrayOutputStream();
CipherOutputStream ciOut = new CipherOutputStream(baOut, cipher);
int c = 0;
while ((c = ciIn.read()) >= 0) {
ciOut.writeCoffee;
}
ciOut.flush();
ciOut.close();
return baOut.toByteArray();
}

public static void main(String[] args) {
try {

KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA",

new org.bouncycastle.jce.provider.
BouncyCastleProvider());
keyPairGen.initialize(1024);
KeyPair keyPair = keyPairGen.genKeyPair();
RSAPublicKey pubKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey priKey = (RSAPrivateKey) keyPair.getPrivate();

Cipher cipher = Cipher.getInstance("RSA",
new org.bouncycastle.jce.
provider.
BouncyCastleProvider());

String s = "1234567890abcdefghijklmnopqrstuvwxyz";

cipher.init(Cipher.ENCRYPT_MODE, priKey);
byte[] bytes = crypt(cipher, s.getBytes());


cipher.init(cipher.DECRYPT_MODE, pubKey);
bytes = crypt(cipher, bytes);
System.out.println(new String(bytes));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
出现以下异常:
Exception in thread "main" java.lang.ExceptionInInitializerError
at javax.crypto.Cipher.a(DashoA6275)
at javax.crypto.Cipher.getInstance(DashoA6275)
at security.RSAEnAndDecrypt.main(RSAEnAndDecrypt.java:41)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
at javax.crypto.SunJCE_b.<clinit>(DashoA6275)
... 3 more
Caused by: java.security.PrivilegedActionException: java.security.NoSuchAlgorith
mException: MD5WITHRSA Signature not available
at java.security.AccessController.doPrivileged(Native Method)
... 4 more
Caused by: java.security.NoSuchAlgorithmException: MD5WITHRSA Signature not avai
lable
at java.security.Security.getEngineClassName(Security.java:584)
at java.security.Security.getEngineClassName(Security.java:595)
at java.security.Security.getImpl(Security.java:1044)
at java.security.Signature.getInstance(Signature.java:169)
at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:425)
at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:383)
at javax.crypto.SunJCE_b.c(DashoA6275)
at javax.crypto.SunJCE_b.b(DashoA6275)
at javax.crypto.SunJCE_s.run(DashoA6275)
... 5 more
Press any key to continue...


317991923 edited on 2004-10-25 22:19

作者 Re:关于BouncyCastle 这个问题 [Re:317991923]
jeffrey_he





发贴: 21
积分: 0
于 2004-10-29 10:36 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
你要指定使用Bouncy castle做为算法提供商,然后才能使用它提供的算法。



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