public static String encrypt ( String c , String key ) { try { SecretKeySpec skeySpec = new SecretKeySpec ( Hex . decodeHex ( key . toCharArray ( ) ) , "AES" ) ; Cipher cipher = Cipher . getInstance ( "AES" ) ; cipher . init ( Cipher . ENCRYPT_MODE , skeySpec ) ; byte [ ] encoded = cipher . doFinal ( c . getBytes ( ) ) ; return new String ( Hex . encodeHex ( encoded ) ) ; } catch ( final Exception e ) { logger . warn ( "Could not encrypt string" , e ) ; return null ; } }
Encrypts a string .