java bouncycastle_Java开发网 - 关于BouncyCastle 这个问题

Posted by:317991923

Posted on:2004-10-25 22:01

刚装完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.write

coffee_smile.gif;

}

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.(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...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值