CryptTool { public static EncryptResult encrypt(byte[] data,byte[] privateKey, byte[] publicKey) { if (publicKey.length != NaCl.PUBLICKEYBYTES || privateKey.length != NaCl.SECRETKEYBYTES) { throw new IllegalArgumentException("Wrong key length"); } byte[] nonce = randomNonce(); NaCl naCl = new NaCl(privateKey, publicKey); return new EncryptResult(naCl.encrypt(data, nonce), null, nonce); }  static EncryptResult encryptTextMessage(String text, byte[] senderPrivateKey, byte[] recipientPublicKey); static EncryptResult encryptImageMessage(EncryptResult encryptResult, UploadResult uploadResult, byte[] senderPrivateKey, byte[] recipientPublicKey); static EncryptResult encryptFileMessage(EncryptResult encryptResult,
	                                               UploadResult uploadResult,
	                                               String mimeType,
	                                               String fileName,
	                                               int fileSize,
	                                               UploadResult uploadResultThumbnail,
	                                               byte[] senderPrivateKey, byte[] recipientPublicKey); static byte[] decrypt(byte[] box, byte[] privateKey, byte[] publicKey, byte[] nonce); static byte[] decryptFileData(byte[] fileData, byte[] secret); static byte[] decryptFileThumbnailData(byte[] fileData, byte[] secret); static ThreemaMessage decryptMessage(byte[] box,  byte[] recipientPrivateKey, byte[] senderPublicKey, byte[] nonce); static void generateKeyPair(byte[] privateKey, byte[] publicKey); static EncryptResult encrypt(byte[] data,byte[] privateKey, byte[] publicKey); static EncryptResult encryptFileData(byte[] data); static EncryptResult encryptFileThumbnailData(byte[] data, byte[] encryptionKey); static byte[] hashEmail(String email); static byte[] hashPhoneNo(String phoneNo); static byte[] randomNonce(); static byte[] derivePublicKey(byte[] privateKey);  }
@Test public void testEncrypt() throws Exception { String text = "Dies ist eine Testnachricht. äöü"; String nonce = "0a1ec5b67b4d61a1ef91f55e8ce0471fee96ea5d8596dfd0"; Key privateKey = Key.decodeKey(Common.myPrivateKey); Key publicKey = Key.decodeKey(Common.otherPublicKey); EncryptResult res = CryptTool.encryptTextMessage(text, privateKey.key, publicKey.key); Assert.assertNotNull(res); Assert.assertNotNull(res.getNonce()); Assert.assertNotNull(res.getResult()); Assert.assertFalse(Common.isEmpty(res.getNonce())); Assert.assertFalse(Common.isEmpty(res.getResult())); }