Created
June 30, 2017 12:50
-
-
Save trevorbernard/6e3a8af0092cdced0f8b3e757a5b6b16 to your computer and use it in GitHub Desktop.
JeroMQ Curve Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.zeromq.ZContext; | |
import org.zeromq.ZMQ; | |
import org.zeromq.ZMQ.Socket; | |
import zmq.io.mechanism.curve.Curve; | |
public class Security { | |
public static void main(String[] args) throws Exception { | |
Curve curve = new Curve(); | |
String[] serverKeys = curve.keypairZ85(); | |
String[] clientKeys = curve.keypairZ85(); | |
ZContext context = new ZContext(); | |
Socket server = context.createSocket(ZMQ.PUSH); | |
server.setAsServerCurve(true); | |
server.setCurvePublicKey(serverKeys[0].getBytes()); | |
server.setCurveSecretKey(serverKeys[1].getBytes()); | |
server.bind("tcp://*:7210"); | |
Socket client = context.createSocket(ZMQ.PULL); | |
client.setCurvePublicKey(clientKeys[0].getBytes()); | |
client.setCurveSecretKey(clientKeys[1].getBytes()); | |
client.setCurveServerKey(serverKeys[0].getBytes()); | |
client.connect("tcp://127.0.0.1:7210"); | |
server.send("Hello, World!"); | |
System.out.println(client.recvStr()); | |
client.close(); | |
server.close(); | |
context.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that the example is slightly outdated, because
createSocket(ZMQ.PUSH)
andserver.setAsServerCurve(true);
are marked as deprecated.I think it should be: