JCEInstallTest.java
上传用户:mbg588933
上传日期:2022-08-05
资源大小:10k
文件大小:1k
源码类别:

加密解密

开发平台:

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.");