· 9 years ago · Jan 31, 2017, 08:40 AM
1public static String encrypt(String data, byte[] secretKey) throws Exception {
2 Key key = generateKey(secretKey);
3 Cipher c = Cipher.getInstance(ALGORITHM);
4 c.init(Cipher.ENCRYPT_MODE, key);
5 byte[] encVal = c.doFinal(data.getBytes());
6 String encryptedValue = new BASE64Encoder().encode(encVal);
7 if (logger.isDebugEnabled()) {
8 logger.debug(String.format("DataToEncrypt: %s, encryptedValue: %s", data, encryptedValue));
9 }
10 return encryptedValue;
11}