Sharing messages

When you encrypt a message, you need to send it somewhere so it can be decrypted, and you can export it to do it easier.

Exporting

To export the Message object, you transform it to a JSON string:

import nim_kyber/big

# Create the message sender with knowo values for publicTable and publicKeys
var ms: KyberSender = createMessageSender(k.publicTable, k.publicKeys);
var m = ms.sendString("Hello"); # Encrypt string message
var str: string = m.exportMessage(); # Export message to JSON string

Now share the str variable, which can be imported as done in the next example.

Importing

To import the Message object from a string, use importMessage.

import nim_kyber/big

var str = "..." # The exported JSON string
var im: Message = importMessage(str);

Now you can use decrypt the message with k.recieveString as show here.

Last updated