public static String unprotect ( String data ) { if ( data == null ) return null ; try { Cipher cipher = Secret . getCipher ( ALGORITHM ) ; cipher . init ( Cipher . DECRYPT_MODE , DES_KEY ) ; String plainText = new String ( cipher . doFinal ( Base64 . getDecoder ( ) . decode ( data . getBytes ( StandardCharsets . UTF_8 ) ) ) , StandardCharsets . UTF_8 ) ; if ( plainText . endsWith ( MAGIC ) ) return plainText . substring ( 0 , plainText . length ( ) - 3 ) ; return null ; } catch ( GeneralSecurityException | IllegalArgumentException e ) { return null ; } }
Returns null if fails to decrypt properly .