JCEInstallTest.java
Upload User: mbg588933
Upload Date: 2022-08-05
Package Size: 10k
Code Size: 1k
Development Platform:

Java

  1. import javax.crypto.*; 
  2. public class JCEInstallTest{ 
  3. public static final String stringToEncrypt="This is a test."; 
  4. public static void main(String[] args) throws Exception{ 
  5.   
  6. System.out.print("Attempting to get a Blowfish key..."); 
  7. KeyGenerator keyGenerator=KeyGenerator.getInstance("Blowfish"); 
  8. keyGenerator.init(128); 
  9. SecretKey key=keyGenerator.generateKey(); 
  10. System.out.println("OK      "+ key.getAlgorithm()); 
  11.   
  12. System.out.println("Attempting to get a Cipher and encrypt..."); 
  13. Cipher cipher=Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); 
  14. cipher.init(Cipher.ENCRYPT_MODE,key); 
  15.   
  16. byte[] cipherText=cipher.doFinal(stringToEncrypt.getBytes("UTF8")); 
  17. System.out.println("OK"); 
  18.   
  19. System.out.println("Test completed successfully.");