Using The Java Library
Configuration
On Android:
dependencies {
compile 'org.whispersystems:signal-protocol-android:(latest version number)'
}
For pure Java apps:
<dependency>
<groupId>org.whispersystems</groupId>
<artifactId>signal-protocol-java</artifactId>
<version>(latest version number)</version>
</dependency>
Install time
At install time, a libsignal-protocol client needs to generate its identity keys, registration id, and
prekeys.
IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();
int registrationId = KeyHelper.generateRegistrationId();
List<PreKeyRecord> preKeys = KeyHelper.generatePreKeys(startId, 100);
PreKeyRecord lastResortKey = KeyHelper.generateLastResortKey();
SignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 5);
// Store identityKeyPair somewhere durable and safe.
// Store registrationId somewhere durable and safe.
// Store preKeys in PreKeyStore.
// Store signed prekey in SignedPreKeyStore.
Building a session
A libsignal-protocol client needs to implement the SignalProtocolStore
interface. This will manage loading and storing of identity, prekeys, signed prekeys, and session state.
Once those are implemented, building a session is fairly straightforward:
SignalProtocolStore signalProtocolStore = new MySignalProtocolStore();
// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
SessionBuilder sessionBuilder = new SessionBuilder(signalProtocolStore,
recipientId,
deviceId);
// Build a session with a PreKey retrieved from the server.
sessionBuilder.process(retrievedPreKey);
// Encrypt a message
SessionCipher sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);
CiphertextMessage message = sessionCipher.encrypt("Hello world!".getBytes("UTF-8"));
// Deliver the message using whatever transport you'd like!
deliver(message.serialize());
Updated less than a minute ago