TokenEncryptor { public Token decrypt(String encryptedToken) throws TokenDecryptionException { if (encryptedToken == null) { throw new NullPointerException("encryptedToken is null!"); } else if ( encryptedToken.isEmpty() ) { throw new TokenDecryptionException("Cannot decrypt emnpty token"); } byte[] encryptedTokenBytes = Base64.decodeBase64(encryptedToken); try { cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParamSpec); byte[] decryptedTokenBytes = cipher.doFinal(encryptedTokenBytes); ByteArrayInputStream memInputStream = new ByteArrayInputStream(decryptedTokenBytes); ObjectInputStream in = new ObjectInputStream(memInputStream); Token token = (Token) in.readObject(); in.close(); return token; } catch (Exception e) { log.error("Unable to decrypt token (" + encryptedToken + ")!", e); throw new TokenDecryptionException(e); } } TokenEncryptor(String secretKey); String generate(); String encrypt(Token token); Token decrypt(String encryptedToken);  }
@Test public void testDecrypty() throws TokenDecryptionException { Token token = tokenEncryptor.decrypt("eneGKi4Soqsw+1gvL7DjNIYuW02B867KmXGwE51Ubd+jurflJqquNQjciZvEf01raCD3au231wmQaoIlSXtIY5GL7aHAF6ue2bYrrgLOIZYYOprbOTcP6mPgptJtCoiqKurReT1m6zlu22D/1LY8dIxk9+Nlqfvvd2kaDnTz8Y3fd64as9+7o1vxOQmcXn/gijAKIfpiZjPkQ8+azOZLwqOT0eIC7ZWlHU4ITQUDKhVef0kVn1CC+3HDzs0q4GtiNL3Jd7hs0/r+dWVwLbZzzc9FnFsTu6nDMz75k6nNICE="); System.out.println("userId=" + token.getUserId()); System.out.println("expiresAt=" + token.getExpiresAt()); }