{"__v":4,"_id":"553ea5bd6ab7691900ee7226","category":{"__v":2,"_id":"553ea5456ab7691900ee7223","pages":["553ea5bd6ab7691900ee7226","553fc45976155d0d005085c5"],"project":"553e9f6a6ab7691900ee7209","version":"553e9f6a6ab7691900ee720c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-27T21:08:21.366Z","from_sync":false,"order":1,"slug":"axolotl-api","title":"Signal Protocol API"},"project":"553e9f6a6ab7691900ee7209","user":"553e9f0c6ab7691900ee7207","version":{"__v":5,"_id":"553e9f6a6ab7691900ee720c","project":"553e9f6a6ab7691900ee7209","createdAt":"2015-04-27T20:43:22.948Z","releaseDate":"2015-04-27T20:43:22.948Z","categories":["553e9f6b6ab7691900ee720d","553e9fca6ab7691900ee7210","553ea5456ab7691900ee7223","56fed4c349408d0e0043c6fb","5807b2ed2ce233230086a6dc"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["56b23bb194ab060d000673e6"],"next":{"pages":[],"description":""},"createdAt":"2015-04-27T21:10:21.554Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"## Configuration\n\nOn Android: \n\n```\ndependencies {\n  compile 'org.whispersystems:signal-protocol-android:(latest version number)'\n}\n```\n\nFor pure Java apps:\n\n```\n<dependency>\n  <groupId>org.whispersystems</groupId>\n  <artifactId>signal-protocol-java</artifactId>\n  <version>(latest version number)</version>\n</dependency>\n```\n\n## Install time\n\nAt install time, a libsignal-protocol client needs to generate its identity keys, registration id, and\nprekeys.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"IdentityKeyPair    identityKeyPair = KeyHelper.generateIdentityKeyPair();\\nint                registrationId  = KeyHelper.generateRegistrationId();\\nList<PreKeyRecord> preKeys         = KeyHelper.generatePreKeys(startId, 100);\\nPreKeyRecord       lastResortKey   = KeyHelper.generateLastResortKey();\\nSignedPreKeyRecord signedPreKey    = KeyHelper.generateSignedPreKey(identityKeyPair, 5);\\n\\n// Store identityKeyPair somewhere durable and safe.\\n// Store registrationId somewhere durable and safe.\\n\\n// Store preKeys in PreKeyStore.\\n// Store signed prekey in SignedPreKeyStore.\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n\n## Building a session\n\nA libsignal-protocol client needs to implement the `SignalProtocolStore` interface.  This will manage loading and storing of identity, prekeys, signed prekeys, and session state.\n\nOnce those are implemented, building a session is fairly straightforward:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SignalProtocolStore signalProtocolStore = new MySignalProtocolStore();\\n\\n// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.\\nSessionBuilder sessionBuilder = new SessionBuilder(signalProtocolStore,\\n                                                   recipientId, \\n                                                   deviceId);\\n\\n// Build a session with a PreKey retrieved from the server.\\nsessionBuilder.process(retrievedPreKey);\\n\\n// Encrypt a message\\nSessionCipher     sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);\\nCiphertextMessage message       = sessionCipher.encrypt(\\\"Hello world!\\\".getBytes(\\\"UTF-8\\\"));\\n\\n// Deliver the message using whatever transport you'd like!\\ndeliver(message.serialize());\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"axolotl-java-library","type":"basic","title":"Using The Java Library"}

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. [block:code] { "codes": [ { "code": "IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();\nint registrationId = KeyHelper.generateRegistrationId();\nList<PreKeyRecord> preKeys = KeyHelper.generatePreKeys(startId, 100);\nPreKeyRecord lastResortKey = KeyHelper.generateLastResortKey();\nSignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 5);\n\n// Store identityKeyPair somewhere durable and safe.\n// Store registrationId somewhere durable and safe.\n\n// Store preKeys in PreKeyStore.\n// Store signed prekey in SignedPreKeyStore.", "language": "java" } ] } [/block] ## 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: [block:code] { "codes": [ { "code": "SignalProtocolStore signalProtocolStore = new MySignalProtocolStore();\n\n// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.\nSessionBuilder sessionBuilder = new SessionBuilder(signalProtocolStore,\n recipientId, \n deviceId);\n\n// Build a session with a PreKey retrieved from the server.\nsessionBuilder.process(retrievedPreKey);\n\n// Encrypt a message\nSessionCipher sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);\nCiphertextMessage message = sessionCipher.encrypt(\"Hello world!\".getBytes(\"UTF-8\"));\n\n// Deliver the message using whatever transport you'd like!\ndeliver(message.serialize());\n", "language": "java" } ] } [/block]