public byte[] decodeCiphertext(byte[] receivedMAC, byte[] additionalData, byte[] ciphertext) throws IOException { KeyParameter macKey = initRecordMAC(decryptCipher); byte[] calculatedMAC = PolyKeyCreator.create(macKey, additionalData, ciphertext); if (!Arrays.constantTimeAreEqual(calculatedMAC, receivedMAC)) { throw new TlsFatalAlert(AlertDescription.bad_record_mac); } byte[] output = new byte[ciphertext.length]; decryptCipher.processBytes(ciphertext, 0, ciphertext.length, output, 0); return output; }
public void send(byte[] buf, int off, int len) throws IOException { if (len > getSendLimit()) { throw new TlsFatalAlert(AlertDescription.record_overflow); } DatagramPacket packet = new DatagramPacket(buf, off, len); socket.send(packet); }