Some days ago I find this information about (I can not remind where did I take it, maybe was from this forum) for install JCE and BouncyCastle software for encryption.
You should first download change the policy of the JCE By downloading this
http://java.sun.com/j2se/1.4.2/download.html just JCE a and unzip in a folder read the read me doc so you should cut that 2 file and put here C:\j2sdk1.4.2_02\jre\lib\security
and here C:\Program Files\Java\j2re1.4.2_02\lib\security
done this then download the bouncy jar file from http://www.bouncycastle.org/latest_releases.html take the bcprov-jdk14-120.jar and put in following directories
C:\j2sdk1.4.2_02\jre\lib\ext
C:\Program Files\Java\j2re1.4.2_02\lib\ext
then you need to change the environment variable so in the following directories open "java.security" in both
C:\j2sdk1.4.2_02\jre\lib\security
C:\Program Files\Java\j2re1.4.2_02\lib\security
and edit it and add the extra line
security.provider.numberProvider=org.bouncycastle.jce.provider.BouncyCastleProv ider
Then you should test if everything is good installed:
And you will see if there is RSA. (It should)
An example:
Encription:
Desencryption:
I am sure you can find many examples of encrypt and decrypt. But hope this help as introduction.
- Susana
You should first download change the policy of the JCE By downloading this
http://java.sun.com/j2se/1.4.2/download.html just JCE a and unzip in a folder read the read me doc so you should cut that 2 file and put here C:\j2sdk1.4.2_02\jre\lib\security
and here C:\Program Files\Java\j2re1.4.2_02\lib\security
done this then download the bouncy jar file from http://www.bouncycastle.org/latest_releases.html take the bcprov-jdk14-120.jar and put in following directories
C:\j2sdk1.4.2_02\jre\lib\ext
C:\Program Files\Java\j2re1.4.2_02\lib\ext
then you need to change the environment variable so in the following directories open "java.security" in both
C:\j2sdk1.4.2_02\jre\lib\security
C:\Program Files\Java\j2re1.4.2_02\lib\security
and edit it and add the extra line
security.provider.numberProvider=org.bouncycastle.jce.provider.BouncyCastleProv ider
Then you should test if everything is good installed:
import java.security.Provider; import java.security.Security; import java.util.Set; import java.util.Iterator; public class Verifica { public static void main(String[] args) { Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { Provider provider = providers[i]; System.out.println("Provider name: " + provider.getName()); System.out.println("Provider information: " + provider.getInfo()); System.out.println("Provider version: " + provider.getVersion()); Set entries = provider.entrySet(); Iterator iterator = entries.iterator(); /*while (iterator.hasNext()) { System.out.println("Property entry: " + iterator.next()); }*/ } }
And you will see if there is RSA. (It should)
An example:
Encription:
//Object Cipher to encript data. Cipher encriptDatos = Cipher.getInstance("RSA", "BC"); encriptDatos.init(Cipher.ENCRYPT_MODE, servidorPub); //servidorPub is the server public key you should have or generate //data encryption byte[] datosEncriptados = encriptDatos.doFinal(b);
Desencryption:
Cipher Cipherdesencriptacion = Cipher.getInstance("RSA", "BC"); Cipherdesencriptacion.init(Cipher.DECRYPT_MODE, servidorPriv); //ServidorPriv is the server public key
//data desencryption byte[] datosClaros = Cipherdesencriptacion.doFinal(datos); //datos = encripted data.
I am sure you can find many examples of encrypt and decrypt. But hope this help as introduction.
- Susana