1.安裝bouncycastle.jar檔案
找到該檔案,並執行以下兩步:
(1)將該檔案拷貝到jdk1.3.1/jre/lib/ext/目錄下
(2)將該檔案拷貝到c:/programfiles/JavaSoft/JRE/1.3/lib/ext目錄下。
注意,以上兩步均要完成,少一不可。
2.配置java.security檔案
首先要找到以下兩個檔案:
(1)jdk1.3.1/jre/lib/security/java.security檔案
(2)c:/programfiles/JavaSoft/JRE/1.3/lib/security/java.security
開啟以上兩個檔案,並找到這樣的語句:
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.rsajca.provider
在上面語句的後面加上如下語句:
security.provider.3=org.bouncycastle.jce.provider.BouncyCastleProvider
要注意的是:
(1)兩個檔案中都要改。
(2)大小寫不能有錯。
3.安裝正確與否的測試
看是否有JCEInstallTest.java程式,分兩種情況:
(1)有該程式
您對它進行編譯並運行。如下:
a.javac JCEInstallTest.java
b.java JCEInstallTest
注意大小寫,如果產生了輸出,則說明安裝正確。否則按前面的步驟檢查錯誤。
(2)沒有該程式
則您可以從本文檔中拷貝一份本程式,在按照有該程式的情況來進行編譯運行。
JCEInstallTest.java程式的代碼如下:
**************************JCEInstallTest.java***************************
import javax.crypto.*;
public class JCEInstallTest{
public static final String stringToEncrypt="This is a test.";
public static void main(String[] args) throws Exception{
System.out.print("Attempting to get a Blowfish key...");
KeyGenerator keyGenerator=KeyGenerator.getInstance("Blowfish");
keyGenerator.init(128);
SecretKey key=keyGenerator.generateKey();
System.out.println("OK");
System.out.println("Attempting to get a Cipher and encrypt...");
Cipher cipher=Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE,key);
byte[] cipherText=cipher.doFinal(stringToEncrypt.getBytes("UTF8"));
System.out.println("OK");
System.out.println("Test completed successfully.");
}
}
****************************JCEInstallTest.java*************************