private byte[] receiveSignedBytes(int playerId, boolean verify) { byte[] message = readInsecuredBytes(playerId); byte[] signature = readInsecuredBytes(playerId); if (!verify || rsaKeys.verify(playerId, new String(message), signature)) { return message; } return null; }
public void sendSignedMessageToAll(String message) { byte[] signature = rsaKeys.sign(message); for (int i = 0; i < playerCount; i++) { if (i != localId) { sendInsecuredMessage(message, i); sendInsecuredBytes(signature, i); } } }
private void sendSignedBytes(byte[] data, int playerId) { OutputStream out = cm.getOutputStream(playerId); DataOutputStream dos = new DataOutputStream(out); try { dos.writeInt(data.length); dos.write(data); byte[] signature = rsaKeys.sign(new String(data)); dos.writeInt(signature.length); dos.write(signature); } catch (IOException e) { e.printStackTrace(); } }