public static SignedPreKeyRecord generateSignedPreKey( Context context, MasterSecret masterSecret, IdentityKeyPair identityKeyPair) { try { SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context, masterSecret); int signedPreKeyId = getNextSignedPreKeyId(context); ECKeyPair keyPair = Curve.generateKeyPair(); byte[] signature = Curve.calculateSignature( identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize()); SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature); signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record); setNextSignedPreKeyId(context, (signedPreKeyId + 1) % Medium.MAX_VALUE); return record; } catch (InvalidKeyException e) { throw new AssertionError(e); } }