Java Code Examples for org.whispersystems.libsignal.ecc.ECKeyPair#getPrivateKey()

The following examples show how to use org.whispersystems.libsignal.ecc.ECKeyPair#getPrivateKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdentityKeyUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static void generateIdentityKeys(Context context) {
  ECKeyPair    djbKeyPair     = Curve.generateKeyPair();
  IdentityKey  djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
  ECPrivateKey djbPrivateKey  = djbKeyPair.getPrivateKey();

  save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(djbIdentityKey.serialize()));
  save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(djbPrivateKey.serialize()));
}
 
Example 2
Source File: MasterSecretUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static AsymmetricMasterSecret generateAsymmetricMasterSecret(Context context,
                                                                    MasterSecret masterSecret)
{
  MasterCipher masterCipher = new MasterCipher(masterSecret);
  ECKeyPair    keyPair      = Curve.generateKeyPair();

  if (!context.getSharedPreferences(PREFERENCES_NAME, 0).edit()
      .putString(ASYMMETRIC_LOCAL_PUBLIC_DJB, Base64.encodeBytes(masterCipher.encryptPublicKey(keyPair.getPublicKey())))
      .putString(ASYMMETRIC_LOCAL_PRIVATE_DJB, Base64.encodeBytes(masterCipher.encryptPrivateKey(keyPair.getPrivateKey())))
      .commit()) {
    throw new AssertionError("failed to save preferences in MasterSecretUtil");
  }

  return new AsymmetricMasterSecret(keyPair.getPublicKey(), keyPair.getPrivateKey());
}
 
Example 3
Source File: IdentityKeyUtil.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static ECKeyPair generateIdentityKeys(AccountContext accountContext) {
    ECKeyPair djbKeyPair = BCMPrivateKeyUtils.INSTANCE.generateKeyPair();
    IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
    ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();

    save(accountContext, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(djbIdentityKey.serialize()));
    save(accountContext, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(djbPrivateKey.serialize()));

    return djbKeyPair;
}
 
Example 4
Source File: MasterSecretUtil.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static AsymmetricMasterSecret generateAsymmetricMasterSecret(@NonNull AccountContext accountContext,
                                                                    MasterSecret masterSecret) {
    MasterCipher masterCipher = new MasterCipher(masterSecret);
    ECKeyPair keyPair = Curve.generateKeyPair();

    save(accountContext, ASYMMETRIC_LOCAL_PUBLIC_DJB, keyPair.getPublicKey().serialize());
    save(accountContext, ASYMMETRIC_LOCAL_PRIVATE_DJB, masterCipher.encryptKey(keyPair.getPrivateKey()));

    return new AsymmetricMasterSecret(keyPair.getPublicKey(), keyPair.getPrivateKey());
}
 
Example 5
Source File: MasterSecretUtil.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public static AsymmetricMasterSecret generateAsymmetricMasterSecret(Context context,
                                                                    MasterSecret masterSecret)
{
  MasterCipher masterCipher = new MasterCipher(masterSecret);
  ECKeyPair    keyPair      = Curve.generateKeyPair();

  save(context, ASYMMETRIC_LOCAL_PUBLIC_DJB, keyPair.getPublicKey().serialize());
  save(context, ASYMMETRIC_LOCAL_PRIVATE_DJB, masterCipher.encryptKey(keyPair.getPrivateKey()));

  return new AsymmetricMasterSecret(keyPair.getPublicKey(), keyPair.getPrivateKey());
}
 
Example 6
Source File: SessionCipherTest.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
private void initializeSessionsV3(SessionState aliceSessionState, SessionState bobSessionState)
    throws InvalidKeyException
{
  ECKeyPair       aliceIdentityKeyPair = Curve.generateKeyPair();
  IdentityKeyPair aliceIdentityKey     = new IdentityKeyPair(new IdentityKey(aliceIdentityKeyPair.getPublicKey()),
                                                             aliceIdentityKeyPair.getPrivateKey());
  ECKeyPair       aliceBaseKey         = Curve.generateKeyPair();
  ECKeyPair       aliceEphemeralKey    = Curve.generateKeyPair();

  ECKeyPair alicePreKey = aliceBaseKey;

  ECKeyPair       bobIdentityKeyPair = Curve.generateKeyPair();
  IdentityKeyPair bobIdentityKey       = new IdentityKeyPair(new IdentityKey(bobIdentityKeyPair.getPublicKey()),
                                                             bobIdentityKeyPair.getPrivateKey());
  ECKeyPair       bobBaseKey           = Curve.generateKeyPair();
  ECKeyPair       bobEphemeralKey      = bobBaseKey;

  ECKeyPair       bobPreKey            = Curve.generateKeyPair();

  AliceSignalProtocolParameters aliceParameters = AliceSignalProtocolParameters.newBuilder()
                                                                               .setOurBaseKey(aliceBaseKey)
                                                                               .setOurIdentityKey(aliceIdentityKey)
                                                                               .setTheirOneTimePreKey(Optional.<ECPublicKey>absent())
                                                                               .setTheirRatchetKey(bobEphemeralKey.getPublicKey())
                                                                               .setTheirSignedPreKey(bobBaseKey.getPublicKey())
                                                                               .setTheirIdentityKey(bobIdentityKey.getPublicKey())
                                                                               .create();

  BobSignalProtocolParameters bobParameters = BobSignalProtocolParameters.newBuilder()
                                                                         .setOurRatchetKey(bobEphemeralKey)
                                                                         .setOurSignedPreKey(bobBaseKey)
                                                                         .setOurOneTimePreKey(Optional.<ECKeyPair>absent())
                                                                         .setOurIdentityKey(bobIdentityKey)
                                                                         .setTheirIdentityKey(aliceIdentityKey.getPublicKey())
                                                                         .setTheirBaseKey(aliceBaseKey.getPublicKey())
                                                                         .create();

  RatchetingSession.initializeSession(aliceSessionState, aliceParameters);
  RatchetingSession.initializeSession(bobSessionState, bobParameters);
}
 
Example 7
Source File: SQLiteAxolotlStore.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private static IdentityKeyPair generateIdentityKeyPair() {
    Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair...");
    ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();
    return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()),
            identityKeyPairKeys.getPrivateKey());
}
 
Example 8
Source File: TestInMemorySignalProtocolStore.java    From libsignal-protocol-java with GNU General Public License v3.0 4 votes vote down vote up
private static IdentityKeyPair generateIdentityKeyPair() {
  ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();

  return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()),
                                             identityKeyPairKeys.getPrivateKey());
}
 
Example 9
Source File: TestInMemoryIdentityKeyStore.java    From libsignal-protocol-java with GNU General Public License v3.0 4 votes vote down vote up
private static IdentityKeyPair generateIdentityKeyPair() {
  ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();

  return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()),
                             identityKeyPairKeys.getPrivateKey());
}
 
Example 10
Source File: SQLiteAxolotlStore.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private static IdentityKeyPair generateIdentityKeyPair() {
	Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair...");
	ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();
	return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()),
			identityKeyPairKeys.getPrivateKey());
}
 
Example 11
Source File: KeyHelper.java    From libsignal-protocol-java with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Generate an identity key pair.  Clients should only do this once,
 * at install time.
 *
 * @return the generated IdentityKeyPair.
 */
public static IdentityKeyPair generateIdentityKeyPair() {
  ECKeyPair   keyPair   = Curve.generateKeyPair();
  IdentityKey publicKey = new IdentityKey(keyPair.getPublicKey());
  return new IdentityKeyPair(publicKey, keyPair.getPrivateKey());
}