@Test public void encodeDecodeUrlSafe() { byte[] bytes = new byte[] { (byte) 0xfb, (byte) 0xf0 }; assertArrayEquals("-_A=".getBytes(), Base64Utils.encodeUrlSafe(bytes)); assertArrayEquals(bytes, Base64Utils.decodeUrlSafe(Base64Utils.encodeUrlSafe(bytes))); assertEquals("-_A=", Base64Utils.encodeToUrlSafeString(bytes)); assertArrayEquals(bytes, Base64Utils.decodeFromUrlSafeString(Base64Utils.encodeToUrlSafeString(bytes))); }
/** * Generates a random 32 character token to be used in URLs. * * @return a token. */ public static String getRandomUrlToken() { SecureRandom sr = new SecureRandom(); byte[] tokenBytes = new byte[ URL_RANDOM_TOKEN_LENGTH ]; sr.nextBytes( tokenBytes ); return Base64Utils.encodeToUrlSafeString( tokenBytes ); } }
/** * Generate the connection id for the connection used by the rule's * connection factory. * @return the id. */ public String generateId() { UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[SIXTEEN]); bb.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "SpringBrokerRunning." + Base64Utils.encodeToUrlSafeString(bb.array()).replaceAll("=", ""); }
@Override public String generateName() { UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); // NOSONAR - Magic # deprecated anyway bb.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); // Convert to base64 and remove trailing = return this.prefix + Base64Utils.encodeToUrlSafeString(bb.array()) .replaceAll("=", ""); }
@Override public String generateName() { UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[SIXTEEN]); bb.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); // Convert to base64 and remove trailing = return this.prefix + Base64Utils.encodeToUrlSafeString(bb.array()) .replaceAll("=", ""); }
/** * Generate the connection id for the connection used by the rule's * connection factory. * @return the id. */ public String generateId() { UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[SIXTEEN]); bb.putLong(uuid.getMostSignificantBits()) .putLong(uuid.getLeastSignificantBits()); return "SpringBrokerRunning." + Base64Utils.encodeToUrlSafeString(bb.array()).replaceAll("=", ""); }