libsignal-protocol-java icon indicating copy to clipboard operation
libsignal-protocol-java copied to clipboard

Simple encryption and decryption

Open pwablito opened this issue 3 years ago • 1 comments

I am trying to use the signal library to make a very simple command line program to encrypt a message and print out the results so that I can then easily decrypt the message on the same system without sending anything back and forth through a server. What is the easiest way to do this? Anywhere I could look that this has already been done? Thanks in advance for any help anyone can offer!

pwablito avatar Oct 21 '21 18:10 pwablito

this should be simple...from the readme, do the following:

SessionStore      sessionStore      = new MySessionStore();
PreKeyStore       preKeyStore       = new MyPreKeyStore();
SignedPreKeyStore signedPreKeyStore = new MySignedPreKeyStore();
IdentityKeyStore  identityStore     = new MyIdentityKeyStore();

// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
                                                   identityStore, recipientId, deviceId);

// Build a session with a PreKey retrieved from the server.
sessionBuilder.process(retrievedPreKey);

SessionCipher     sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);
CiphertextMessage message      = sessionCipher.encrypt("Hello world!".getBytes("UTF-8"));

deliver(message.serialize());

What you need to provide are the stores' implementation i.e sessionStore, preKeyStore, signedPreKeyStore & identityStore.

Implement the deliver method to send the encrypted bytes wherever you want

tomiamao avatar Nov 24 '21 15:11 tomiamao