sun的加密api包里面不就有么!
解决方案 »
- 我写的一个Hibernate程序,many-to-one的。求大家指点
- ssh框架搭建问题
- 在myeclipse中怎样安装struct?
- 十万火急 用 Jetty 发生报错,tomcat没问题
- Struts2+Hibernate+Spring 事物 Session is closed!
- 求hibernate继承映射
- 有哪位同仁用过openedit?有什么好的建议和文档,分享一下,多谢.
- 求助:weblogic8.1中的一个问题,急?????
- 用java编写的网页,中间件用EJB,向编写一个登陆界面,各类bean怎么编写?有建议么?
- java udp丢包严重
- 关于一个类只能生成它的唯一实例的问题..(急,在线等待,解决了立刻给分~~)
- 如何用struts一次上传多个文件??
我编译时报错
java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA
at javax.crypto.Cipher.getInstance(DashoA6275)
java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA
at javax.crypto.Cipher.getInstance(DashoA6275)
请问大侠,我该怎么办?
谢谢!
1、 将bcprov-jdk14-120.jar复制到D:\j2sdk1.4.1_03\jre\lib\ext目录和D:\Program Files\Java\j2re1.4.1_03\lib\ext目录,如果再不行,就将其再复制到ext的上级目录下。
2、 将以上两个目录下的security子目录的java.security文件中增加security.provider.<n>=org.bouncycastle.jce.provider.BouncyCastleProvider,其中<n>根据前面几个提供者的序号递增,例如在j2sdk1.4.1_03中为6。
3、 这样,在java程序中就可以使用RSA加密算法了。以下 摘自IBM开发者论坛的PublicExample.java程序,在没有安装成功Bouncy Castle提供者时运行提示错误如下:
Exception in thread "main" java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA/ECB/PKCS1Padding
at javax.crypto.Cipher.getInstance(DashoA6275)
at PublicExample.main(PublicExample.java:24)而在安装成功后就可以完好的执行。执行结果如下:
E:\security>java PublicExample "This is a test,这是一个测试!this is a test!"
Start generating RSA key
Finish generating RSA key
BouncyCastle Security Provider v1.19
Start encryption
Finish encryption:
This is a test,这是一个测试!this is a test!源代码如下:
import java.security.*;
import javax.crypto.*;
//
// Public Key cryptography using the RSA algorithm.
public class PublicExample { public static void main (String[] args) throws Exception {
//
// check args and get plaintext
if (args.length !=1) {
System.err.println("Usage: java PublicExample text");
System.exit(1);
}
byte[] plainText = args[0].getBytes("UTF8");
//
// generate an RSA key
System.out.println( "\nStart generating RSA key" );
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair key = keyGen.generateKeyPair();
System.out.println( "Finish generating RSA key" );
//
// get an RSA cipher object and print the provider
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
System.out.println( "\n" + cipher.getProvider().getInfo() );
//
// encrypt the plaintext using the public key
System.out.println( "\nStart encryption" );
cipher.init(Cipher.ENCRYPT_MODE, key.getPublic());
byte[] cipherText = cipher.doFinal(plainText);
System.out.println( "Finish encryption: " );
System.out.println( new String(cipherText, "UTF8") );
//
// decrypt the ciphertext using the private key
System.out.println( "\nStart decryption" );
cipher.init(Cipher.DECRYPT_MODE, key.getPrivate());
byte[] newPlainText = cipher.doFinal(cipherText);
System.out.println( "Finish decryption: " );
System.out.println( new String(newPlainText, "UTF8") );
}
}
你得在java.security文件里面设置!