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 shoshould 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 shocould 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 the 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 shoshould 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 shocould)
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 encryptionbyte[] datosEncriptados = encriptDatos.doFinal(b);
Desencryption:
Cipher Cipherdesencriptacion = Cipher.getInstance("RSA", "BC");Cipherdesencriptacion.init(Cipher.DECRYPT_MODE, servidorPriv); //ServidorPriv is the server public key
//data desencryptionbyte[] datosClaros = Cipherdesencriptacion.doFinal(datos); //datos = encripted data.
I am sure you can find your examples of encrypt and decrypt. But hope this help as introduction.
-Susana