public static String endpointToken(final String uaid, final String channelId, final byte[] key) { try { final String path = uaid + "." + channelId; return encrypt(key, path); } catch (final Exception e) { throw new RuntimeException(e); } }
private String generateEndpointToken(final String uaid, final String channelId) { return CryptoUtil.endpointToken(uaid, channelId, privateKey); }
/** * Decrypts the content passed-in. * * @param key the key used for the underlying cypher. * @param content the content to decrypted. * @return {@code String} the descrypted content as a String. * @throws InvalidKeyException * * @throws Exception */ 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); }
public static byte[] generateAndStorePrivateKey(final DataStore store, final SimplePushServerConfig config) { byte[] keySalt = store.getPrivateKeySalt(); if (keySalt.length == 0) { keySalt = RandomUtils.randomBytes(); store.savePrivateKeySalt(keySalt); } return CryptoUtil.secretKey(config.password(), keySalt); }
/** * Encrypts the content passed-in. * * @param key the key used for the underlying cypher. * @param content the content to encrypted * @return {@code String} the encoded content as base64 url safe encoded string. * * @throws Exception */ public static String encrypt(final byte[] key, final String content) throws Exception { final byte[] iv = BlockCipher.getIV(); final byte[] encrypted = new CryptoBox(key).encrypt(iv, content.getBytes(ASCII)); final String base64 = new UrlBase64().encode(prependIV(encrypted, iv)); return URLEncoder.encode(base64, ASCII.displayName()); }
public static byte[] generateAndStorePrivateKey(final DataStore store, final SimplePushServerConfig config) { byte[] keySalt = store.getPrivateKeySalt(); if (keySalt.length == 0) { keySalt = RandomUtils.randomBytes(); store.savePrivateKeySalt(keySalt); } return CryptoUtil.secretKey(config.password(), keySalt); }
private String generateEndpointToken(final String uaid, final String channelId) { return CryptoUtil.endpointToken(uaid, channelId, privateKey); }