安裝配置BouncyCastle JCE

來源:互聯網
上載者:User

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*************************

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.