CipherUtil { public static byte[] PBEEncrypt(byte[] data,String password,byte[] salt) throws Exception { return PBECipher( data, password, salt, Cipher.ENCRYPT_MODE); }  static byte[] MD5Encrypt(String data); static byte[] SHAEncrypt(String data); static String generateMACKey(); static String generateMACKey(String algorithm); static byte[] HMACEncrypt(byte[] data, String key); static byte[] HMACEncrypt(byte[] data); static String generateDESKey(String seed); static String generateDESKey(); static byte[] DESEncrypt(byte[] data,String key); static byte[] DESDecrypt(byte[] data, String key); static byte[] generatePBESalt(); static byte[] PBEEncrypt(byte[] data,String password,byte[] salt); static byte[] PBEDecrypt(byte[] data,String password,byte[] salt); static String generateAESKey(int keySize,String seed); static String AESEncrypt(String data,String key,String algorithmParameter); static String AESDecrypt(String data,String key,String algorithmParameter); static String RSASign(String data, String privateKey); static boolean RSAVerify(String data, String publicKey, String sign); static String RSADecryptByPrivateKey(String data, String key); static String RSADecryptByPublicKey(String data, String key); static String RSAEncryptByPublicKey(String data, String key); static String RSAEncryptByPrivateKey(String data, String key); static String getRSAPrivateKey(Map<String, Object> keyMap); static String getRSAPublicKey(Map<String, Object> keyMap); static Map<String, Object> initRSAKey(); static Map<String, Object> initDHKey(); static Map<String, Object> initDHKey(String key); static String DHEncrypt(String data, String publicKey,String privateKey); static String DHDecrypt(String data, String publicKey,String privateKey); static String getDHPrivateKey(Map<String, Object> keyMap); static String getDHPublicKey(Map<String, Object> keyMap); static String encryptByPrivateKey(String data, String keyStorePath,
            String alias, String password); static String decryptByPrivateKey(String data, String keyStorePath,String alias, String password); static String encryptByPublicKey(String data, String certificatePath); static String decryptByPublicKey(String data, String certificatePath); static boolean verifyCertificate(String certificatePath); static boolean verifyCertificate(Date date, String certificatePath); static String sign(String sign, String keyStorePath, String alias,String password); static boolean verify(String data, String sign,String certificatePath); static boolean verifyCertificate(Date date, String keyStorePath,
                                            String alias, String password); static boolean verifyCertificate(String keyStorePath, String alias,
                                            String password); static String BASE64Encrypt(byte[] data); static byte[] BASE64Decrypt(String data); static final String ALGORITHM_HMACSHA1; static final String ALGORITHM_HMACSHA256; static final String ALGORITHM_HMACSHA384; static final String ALGORITHM_HMACSHA512; }
@Test public void testPBEEncrypt() throws Exception { System.out.println("content:" + content); byte[] salt = CipherUtil.generatePBESalt(); String password = "cj861105"; System.out.println("password: " + password); byte[] input = content.getBytes(); byte[] data = CipherUtil.PBEEncrypt(input, password, salt); System.out.println("PBEEncrypt = " + CipherUtil.BASE64Encrypt(data)); byte[] output = CipherUtil.PBEDecrypt(data, password, salt); String outputStr = new String(output); System.out.println("PBEDecrypt: " + outputStr); assertEquals(content, outputStr); }