/** * Creates some random bytes * * @param size * Number of random bytes to create * @return random bytes */ static byte[] randomBytes(int size) { byte[] bytes = new byte[size]; for (int i = 0; i < size; i++) { bytes[i] = (byte) randomNumber(0, 255); } return bytes; }
private static String insertSpaces(String key, int spaces) { for (int i = 0; i < spaces; i++) { int split = WebSocketUtil.randomNumber(1, key.length() - 1); String part1 = key.substring(0, split); String part2 = key.substring(split); key = part1 + ' ' + part2; } return key; }
private static String insertRandomCharacters(String key) { int count = WebSocketUtil.randomNumber(1, 12); char[] randomChars = new char[count]; int randCount = 0; while (randCount < count) { int rand = (int) (Math.random() * 0x7e + 0x21); if (0x21 < rand && rand < 0x2f || 0x3a < rand && rand < 0x7e) { randomChars[randCount] = (char) rand; randCount += 1; } } for (int i = 0; i < count; i++) { int split = WebSocketUtil.randomNumber(0, key.length()); String part1 = key.substring(0, split); String part2 = key.substring(split); key = part1 + randomChars[i] + part2; } return key; }
public ChannelFuture handshake(Channel channel) { int spaces1 = WebSocketUtil.randomNumber(1, 12); int spaces2 = WebSocketUtil.randomNumber(1, 12); int number1 = WebSocketUtil.randomNumber(0, max1); int number2 = WebSocketUtil.randomNumber(0, max2);