Coder Social home page Coder Social logo

Setting encryption keys about clrzmq4 HOT 3 CLOSED

zeromq avatar zeromq commented on May 29, 2024
Setting encryption keys

from clrzmq4.

Comments (3)

gillima avatar gillima commented on May 29, 2024

The problem seems to be with the data type of the keys. We use curve for our connections and they work fine when we use ZSocket.SetOption(ZSocketOption.CURVE_... instead of the properties.
Here the example using the test keys from the zmq page:

         this.FrontendSocket.SetOption(ZSocketOption.CURVE_SERVERKEY, @"rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7");
         this.FrontendSocket.SetOption(ZSocketOption.CURVE_PUBLICKEY, @"Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID");
         this.FrontendSocket.SetOption(ZSocketOption.CURVE_SECRETKEY, @"D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs");

Maybe you are aware of this, but be careful with the keys when you paste them for test in your code. When they contain { you must either use the @ in front of the string or escape the { as {{...

from clrzmq4.

metadings avatar metadings commented on May 29, 2024

YEAH... you are right, as long as you are hard-coding these keys... If you have them in a byte[], say from reading from a file, you don't need to escape char[] sequences...

from clrzmq4.

metadings avatar metadings commented on May 29, 2024

This is like "key".ToZ85DecodedBytes()...
You are just getting byte[3] from new char[3] { 'k', 'e', 'y' }... And this is EINVALid...

You should have instead byte[32] from your key data, so you need something like

var privateK = new byte[32];
var publicK = new byte[32];

// make Private key 
using (var rng = new RNGCryptoServiceProvider()) rng.GetBytes(privateK);

// get Public key
crypto.scalarmult_base(publicK, privateK);

socket.SetOption(ZSocketOption.CURVE_SECRETKEY, privateK);
socket.SetOption(ZSocketOption.CURVE_PUBLICKEY, publicK);
// ...

then you also can move your byte[] around with Z85.Encode...

from clrzmq4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.