document:http://www.bouncycastle.org/documentation.html
download:http://www.bouncycastle.org/latest_releases.html ---bcprov-jdk15-138.jar
installation step:
The provider can be configured as part of your environment
via static registration by adding an entry to the java.security
properties file (found in $JAVA_HOME/jre/lib/security/java.security,
where $JAVA_HOME is the location of your JDK/JRE distribution).
You'll find detailed instructions in the file but basically it
comes down to adding a line:
security.provider.<n>=org.bouncycastle.jce.provider.BouncyCastleProvider
Where <n> is the preference you want the provider at (1 being the most prefered).
Note: issues arise if the Sun provided providers are not first.
Where you put the jar is up to mostly up to you, although with jdk1.3 and jdk1.4
the best (and in some cases only) place to have it is in $JAVA_HOME/jre/lib/ext.
Note: under Windows there will normally be a JRE and a JDK install of Java if you
think you have installed it correctly and it still doesn't work chances are you
have added the provider to the installation not being used.
Note: with JDK 1.4 and later you will need to have installed the unrestricted policy
files to take full advantage of the provider. If you do not install the policy files
you are likely to get something like the following:
java.lang.SecurityException: Unsupported keysize or algorithm parameters
at javax.crypto.Cipher.init(DashoA6275)
The policy files can be found at the same place you downloaded the JDK.
test programme:
import java.security.*;
import javax.crypto.*;
import java.util.*;
import java.io.*;
import java.net.*;
import sun.misc.*;
public class testBC{
public static void main(String[] args) throws Exception{
KeyGenerator keyGenerator=KeyGenerator.getInstance("Blowfish");
keyGenerator.init(128);
SecretKey key=keyGenerator.generateKey();
Cipher cipher=Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE,key);
for(int i=1;i<5;i++){
System.out.print("enter the string needed to encrypt:");
byte[] buff = new byte[100];
Scanner scanner = new Scanner(System.in);
String stringToEncrypt = scanner.nextLine();
byte[] cipherText=cipher.doFinal(stringToEncrypt.getBytes("UTF8"));
System.out.print("the string after encrypting is: ");
System.out.println(new BASE64Encoder().encode(cipherText));
}
}
}