@Test public void decrypt() throws Exception { final byte[] salt = "some salt for the server private".getBytes(); final byte[] encryptKey = CryptoUtil.secretKey("key", salt); final String expected = UUID.randomUUID().toString() + "." + UUID.randomUUID().toString(); final String encrypted = CryptoUtil.encrypt(encryptKey, expected); final byte[] decryptKey = CryptoUtil.secretKey("key", salt); assertThat(CryptoUtil.decrypt(decryptKey, encrypted), is(equalTo(expected))); }
public static String decrypt(final byte[] key, final String content) throws Exception { final byte[] decodedContent = new UrlBase64().decode(URLDecoder.decode(content, ASCII.displayName())); final byte[] iv = extractIV(decodedContent); final byte[] decrypted = new CryptoBox(key).decrypt(iv, extractContent(decodedContent)); return new String(decrypted, ASCII); }
CryptoUtil { public static String decrypt(final byte[] key, final String content) throws Exception { final byte[] decodedContent = new UrlBase64().decode(URLDecoder.decode(content, ASCII.displayName())); final byte[] iv = extractIV(decodedContent); final byte[] decrypted = new CryptoBox(key).decrypt(iv, extractContent(decodedContent)); return new String(decrypted, ASCII); } }
CryptoUtil { public static String decrypt(final byte[] key, final String content) throws Exception { final byte[] decodedContent = new UrlBase64().decode(URLDecoder.decode(content, ASCII.displayName())); final byte[] iv = extractIV(decodedContent); final byte[] decrypted = new CryptoBox(key).decrypt(iv, extractContent(decodedContent)); return new String(decrypted, ASCII); } private  CryptoUtil(); }
CryptoUtil { public static String decrypt(final byte[] key, final String content) throws Exception { final byte[] decodedContent = new UrlBase64().decode(URLDecoder.decode(content, ASCII.displayName())); final byte[] iv = extractIV(decodedContent); final byte[] decrypted = new CryptoBox(key).decrypt(iv, extractContent(decodedContent)); return new String(decrypted, ASCII); } private  CryptoUtil(); static String encrypt(final byte[] key, final String content); static String decrypt(final byte[] key, final String content); static byte[] secretKey(final String password, final byte[] salt); static String endpointToken(final String uaid, final String channelId, final byte[] key); }
CryptoUtil { public static String decrypt(final byte[] key, final String content) throws Exception { final byte[] decodedContent = new UrlBase64().decode(URLDecoder.decode(content, ASCII.displayName())); final byte[] iv = extractIV(decodedContent); final byte[] decrypted = new CryptoBox(key).decrypt(iv, extractContent(decodedContent)); return new String(decrypted, ASCII); } private  CryptoUtil(); static String encrypt(final byte[] key, final String content); static String decrypt(final byte[] key, final String content); static byte[] secretKey(final String password, final byte[] salt); static String endpointToken(final String uaid, final String channelId, final byte[] key);  }