@Test public void testEncodeValid() { Map<String, Long> data = new TreeMap<String, Long>(); data.put("s", 888L); data.put("p", 4507L); String token = sut.encode("p4507s888", USER_KEY); assertEquals("X8xF5hXq+v3HsPnb0F5wXw==", token); }
public String encode(final String content, final byte[] keyBytes) { Key key = new SecretKeySpec(keyBytes, algorithm); byte[] encrypted; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); encrypted = cipher.doFinal(content.getBytes()); } catch (GeneralSecurityException ex) { log.error("Error encrypting data into token (data: '{}')", content, ex); return null; } String token = javax.xml.bind.DatatypeConverter.printBase64Binary(encrypted); return token; }
TokenEncoder { public String encode(final String content, final byte[] keyBytes) { Key key = new SecretKeySpec(keyBytes, algorithm); byte[] encrypted; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); encrypted = cipher.doFinal(content.getBytes()); } catch (GeneralSecurityException ex) { log.error("Error encrypting data into token (data: '{}')", content, ex); return null; } String token = javax.xml.bind.DatatypeConverter.printBase64Binary(encrypted); return token; } }
TokenEncoder { public String encode(final String content, final byte[] keyBytes) { Key key = new SecretKeySpec(keyBytes, algorithm); byte[] encrypted; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); encrypted = cipher.doFinal(content.getBytes()); } catch (GeneralSecurityException ex) { log.error("Error encrypting data into token (data: '{}')", content, ex); return null; } String token = javax.xml.bind.DatatypeConverter.printBase64Binary(encrypted); return token; } TokenEncoder(final String inAlgorithm); }
TokenEncoder { public String encode(final String content, final byte[] keyBytes) { Key key = new SecretKeySpec(keyBytes, algorithm); byte[] encrypted; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); encrypted = cipher.doFinal(content.getBytes()); } catch (GeneralSecurityException ex) { log.error("Error encrypting data into token (data: '{}')", content, ex); return null; } String token = javax.xml.bind.DatatypeConverter.printBase64Binary(encrypted); return token; } TokenEncoder(final String inAlgorithm); String encode(final String content, final byte[] keyBytes); boolean couldBeToken(final String potentialToken); String decode(final String token, final byte[] keyBytes); }
TokenEncoder { public String encode(final String content, final byte[] keyBytes) { Key key = new SecretKeySpec(keyBytes, algorithm); byte[] encrypted; try { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); encrypted = cipher.doFinal(content.getBytes()); } catch (GeneralSecurityException ex) { log.error("Error encrypting data into token (data: '{}')", content, ex); return null; } String token = javax.xml.bind.DatatypeConverter.printBase64Binary(encrypted); return token; } TokenEncoder(final String inAlgorithm); String encode(final String content, final byte[] keyBytes); boolean couldBeToken(final String potentialToken); String decode(final String token, final byte[] keyBytes);  }