当前位置: 首页>>代码示例>>Java>>正文


Java ECKeyPair.getPublicKey方法代码示例

本文整理汇总了Java中org.whispersystems.libaxolotl.ecc.ECKeyPair.getPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java ECKeyPair.getPublicKey方法的具体用法?Java ECKeyPair.getPublicKey怎么用?Java ECKeyPair.getPublicKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.whispersystems.libaxolotl.ecc.ECKeyPair的用法示例。


在下文中一共展示了ECKeyPair.getPublicKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encryptBody

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public String encryptBody(String body) {
  try {
    ECPublicKey  theirPublic        = asymmetricMasterSecret.getDjbPublicKey();
    ECKeyPair    ourKeyPair         = Curve.generateKeyPair();
    byte[]       secret             = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
    MasterCipher masterCipher       = getMasterCipherForSecret(secret);
    byte[]       encryptedBodyBytes = masterCipher.encryptBytes(body.getBytes());

    PublicKey    ourPublicKey       = new PublicKey(31337, ourKeyPair.getPublicKey());
    byte[]       publicKeyBytes     = ourPublicKey.serialize();
    byte[]       combined           = Util.combine(publicKeyBytes, encryptedBodyBytes);

    return Base64.encodeBytes(combined);
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:18,代码来源:AsymmetricMasterCipher.java

示例2: process

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
/**
 * Initiate a new session by sending an initial KeyExchangeMessage to the recipient.
 *
 * @return the KeyExchangeMessage to deliver.
 */
public KeyExchangeMessage process() {
  synchronized (SessionCipher.SESSION_LOCK) {
    try {
      int             sequence         = KeyHelper.getRandomSequence(65534) + 1;
      int             flags            = KeyExchangeMessage.INITIATE_FLAG;
      ECKeyPair       baseKey          = Curve.generateKeyPair();
      ECKeyPair       ratchetKey       = Curve.generateKeyPair();
      IdentityKeyPair identityKey      = identityKeyStore.getIdentityKeyPair();
      byte[]          baseKeySignature = Curve.calculateSignature(identityKey.getPrivateKey(), baseKey.getPublicKey().serialize());
      SessionRecord   sessionRecord    = sessionStore.loadSession(recipientId, deviceId);

      sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ratchetKey, identityKey);
      sessionStore.storeSession(recipientId, deviceId, sessionRecord);

      return new KeyExchangeMessage(2, sequence, flags, baseKey.getPublicKey(), baseKeySignature,
                                    ratchetKey.getPublicKey(), identityKey.getPublicKey());
    } catch (InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:27,代码来源:SessionBuilder.java

示例3: createAlicePreKeyBundle

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
private PreKeyBundle createAlicePreKeyBundle(AxolotlStore aliceStore) throws InvalidKeyException {
  ECKeyPair aliceUnsignedPreKey   = Curve.generateKeyPair();
  int       aliceUnsignedPreKeyId = new Random().nextInt(Medium.MAX_VALUE);
  byte[]    aliceSignature        = Curve.calculateSignature(aliceStore.getIdentityKeyPair().getPrivateKey(),
                                                             aliceSignedPreKey.getPublicKey().serialize());

  PreKeyBundle alicePreKeyBundle = new PreKeyBundle(1, 1,
                                                    aliceUnsignedPreKeyId, aliceUnsignedPreKey.getPublicKey(),
                                                    aliceSignedPreKeyId, aliceSignedPreKey.getPublicKey(),
                                                    aliceSignature, aliceStore.getIdentityKeyPair().getPublicKey());

  aliceStore.storeSignedPreKey(aliceSignedPreKeyId, new SignedPreKeyRecord(aliceSignedPreKeyId, System.currentTimeMillis(), aliceSignedPreKey, aliceSignature));
  aliceStore.storePreKey(aliceUnsignedPreKeyId, new PreKeyRecord(aliceUnsignedPreKeyId, aliceUnsignedPreKey));

  return alicePreKeyBundle;
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:17,代码来源:SimultaneousInitiateTests.java

示例4: createBobPreKeyBundle

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
private PreKeyBundle createBobPreKeyBundle(AxolotlStore bobStore) throws InvalidKeyException {
  ECKeyPair bobUnsignedPreKey   = Curve.generateKeyPair();
  int       bobUnsignedPreKeyId = new Random().nextInt(Medium.MAX_VALUE);
  byte[]    bobSignature        = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                           bobSignedPreKey.getPublicKey().serialize());

  PreKeyBundle bobPreKeyBundle = new PreKeyBundle(1, 1,
                                                  bobUnsignedPreKeyId, bobUnsignedPreKey.getPublicKey(),
                                                  bobSignedPreKeyId, bobSignedPreKey.getPublicKey(),
                                                  bobSignature, bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storeSignedPreKey(bobSignedPreKeyId, new SignedPreKeyRecord(bobSignedPreKeyId, System.currentTimeMillis(), bobSignedPreKey, bobSignature));
  bobStore.storePreKey(bobUnsignedPreKeyId, new PreKeyRecord(bobUnsignedPreKeyId, bobUnsignedPreKey));

  return bobPreKeyBundle;
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:17,代码来源:SimultaneousInitiateTests.java

示例5: generateIdentityKeys

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public static void generateIdentityKeys(Context context, MasterSecret masterSecret) {
  ECKeyPair    djbKeyPair     = Curve.generateKeyPair();

  MasterCipher masterCipher   = new MasterCipher(masterSecret);
  IdentityKey  djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
  byte[]       djbPrivateKey  = masterCipher.encryptKey(djbKeyPair.getPrivateKey());

  save(context, IDENTITY_PUBLIC_KEY_DJB_PREF, Base64.encodeBytes(djbIdentityKey.serialize()));
  save(context, IDENTITY_PRIVATE_KEY_DJB_PREF, Base64.encodeBytes(djbPrivateKey));
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:11,代码来源:IdentityKeyUtil.java

示例6: generateCurve25519IdentityKeys

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public static void generateCurve25519IdentityKeys(Context context, MasterSecret masterSecret) {
  MasterCipher masterCipher    = new MasterCipher(masterSecret);
  ECKeyPair    djbKeyPair      = Curve.generateKeyPair();
  IdentityKey  djbIdentityKey  = new IdentityKey(djbKeyPair.getPublicKey());
  byte[]       djbPrivateKey   = masterCipher.encryptKey(djbKeyPair.getPrivateKey());

  save(context, IDENTITY_PUBLIC_KEY_DJB_PREF, Base64.encodeBytes(djbIdentityKey.serialize()));
  save(context, IDENTITY_PRIVATE_KEY_DJB_PREF, Base64.encodeBytes(djbPrivateKey));
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:10,代码来源:IdentityKeyUtil.java

示例7: generateAsymmetricMasterSecret

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
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());
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:12,代码来源:MasterSecretUtil.java

示例8: process

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public SenderKeyDistributionMessage process(String groupId, int keyId, int iteration,
                                            byte[] chainKey, ECKeyPair signatureKey)
{
  synchronized (GroupCipher.LOCK) {
    SenderKeyRecord senderKeyRecord = senderKeyStore.loadSenderKey(groupId);
    senderKeyRecord.setSenderKeyState(keyId, iteration, chainKey, signatureKey);
    senderKeyStore.storeSenderKey(groupId, senderKeyRecord);

    return new SenderKeyDistributionMessage(keyId, iteration, chainKey, signatureKey.getPublicKey());
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:12,代码来源:GroupSessionBuilder.java

示例9: initializeSessionsV2

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
private void initializeSessionsV2(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       bobIdentityKeyPair   = Curve.generateKeyPair();
  IdentityKeyPair bobIdentityKey       = new IdentityKeyPair(new IdentityKey(bobIdentityKeyPair.getPublicKey()),
                                                             bobIdentityKeyPair.getPrivateKey());
  ECKeyPair       bobBaseKey           = Curve.generateKeyPair();
  ECKeyPair       bobEphemeralKey      = bobBaseKey;

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

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

  RatchetingSession.initializeSession(aliceSessionState, 2, aliceParameters);
  RatchetingSession.initializeSession(bobSessionState, 2, bobParameters);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:37,代码来源:SessionCipherTest.java

示例10: initializeSessionsV3

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
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();

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

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

  RatchetingSession.initializeSession(aliceSessionState, 3, aliceParameters);
  RatchetingSession.initializeSession(bobSessionState, 3, bobParameters);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:41,代码来源:SessionCipherTest.java

示例11: InMemoryIdentityKeyStore

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public InMemoryIdentityKeyStore() {
  try {
    ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();

    this.identityKeyPair = new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()),
                                               identityKeyPairKeys.getPrivateKey());
    this.localRegistrationId = SecureRandom.getInstance("SHA1PRNG").nextInt(16380) + 1;
  } catch (NoSuchAlgorithmException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:12,代码来源:InMemoryIdentityKeyStore.java

示例12: generateIdentityKeyPair

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
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());
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:7,代码来源:SQLiteAxolotlStore.java

示例13: SenderKeyState

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public SenderKeyState(int id, int iteration, byte[] chainKey, ECKeyPair signatureKey) {
  this(id, iteration, chainKey, signatureKey.getPublicKey(), Optional.of(signatureKey.getPrivateKey()));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:4,代码来源:SenderKeyState.java

示例14: testRepeatBundleMessageV3

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testRepeatBundleMessageV3() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, NoSessionException {
  AxolotlStore   aliceStore          = new InMemoryAxolotlStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1);

  AxolotlStore bobStore = new InMemoryAxolotlStore();

  ECKeyPair bobPreKeyPair            = Curve.generateKeyPair();
  ECKeyPair bobSignedPreKeyPair      = Curve.generateKeyPair();
  byte[]    bobSignedPreKeySignature = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                                bobSignedPreKeyPair.getPublicKey().serialize());

  PreKeyBundle bobPreKey = new PreKeyBundle(bobStore.getLocalRegistrationId(), 1,
                                            31337, bobPreKeyPair.getPublicKey(),
                                            22, bobSignedPreKeyPair.getPublicKey(), bobSignedPreKeySignature,
                                            bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair));
  bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature));

  aliceSessionBuilder.process(bobPreKey);

  String            originalMessage    = "L'homme est condamné à être libre";
  SessionCipher     aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1);
  CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes());
  CiphertextMessage outgoingMessageTwo = aliceSessionCipher.encrypt(originalMessage.getBytes());

  assertTrue(outgoingMessageOne.getType() == CiphertextMessage.PREKEY_TYPE);
  assertTrue(outgoingMessageTwo.getType() == CiphertextMessage.PREKEY_TYPE);

  PreKeyWhisperMessage incomingMessage = new PreKeyWhisperMessage(outgoingMessageOne.serialize());

  SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1);

  byte[]        plaintext        = bobSessionCipher.decrypt(incomingMessage);
  assertTrue(originalMessage.equals(new String(plaintext)));

  CiphertextMessage bobOutgoingMessage = bobSessionCipher.encrypt(originalMessage.getBytes());

  byte[] alicePlaintext = aliceSessionCipher.decrypt(new WhisperMessage(bobOutgoingMessage.serialize()));
  assertTrue(originalMessage.equals(new String(alicePlaintext)));

  // The test

  PreKeyWhisperMessage incomingMessageTwo = new PreKeyWhisperMessage(outgoingMessageTwo.serialize());

  plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(incomingMessageTwo.serialize()));
  assertTrue(originalMessage.equals(new String(plaintext)));

  bobOutgoingMessage = bobSessionCipher.encrypt(originalMessage.getBytes());
  alicePlaintext = aliceSessionCipher.decrypt(new WhisperMessage(bobOutgoingMessage.serialize()));
  assertTrue(originalMessage.equals(new String(alicePlaintext)));

}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:54,代码来源:SessionBuilderTest.java

示例15: testBadMessageBundle

import org.whispersystems.libaxolotl.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testBadMessageBundle() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, DuplicateMessageException, LegacyMessageException, InvalidKeyIdException {
  AxolotlStore   aliceStore          = new InMemoryAxolotlStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1);

  AxolotlStore bobStore = new InMemoryAxolotlStore();

  ECKeyPair bobPreKeyPair            = Curve.generateKeyPair();
  ECKeyPair bobSignedPreKeyPair      = Curve.generateKeyPair();
  byte[]    bobSignedPreKeySignature = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                                bobSignedPreKeyPair.getPublicKey().serialize());

  PreKeyBundle bobPreKey = new PreKeyBundle(bobStore.getLocalRegistrationId(), 1,
                                            31337, bobPreKeyPair.getPublicKey(),
                                            22, bobSignedPreKeyPair.getPublicKey(), bobSignedPreKeySignature,
                                            bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair));
  bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature));

  aliceSessionBuilder.process(bobPreKey);

  String            originalMessage    = "L'homme est condamné à être libre";
  SessionCipher     aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1);
  CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes());

  assertTrue(outgoingMessageOne.getType() == CiphertextMessage.PREKEY_TYPE);

  byte[] goodMessage = outgoingMessageOne.serialize();
  byte[] badMessage  = new byte[goodMessage.length];
  System.arraycopy(goodMessage, 0, badMessage, 0, badMessage.length);

  badMessage[badMessage.length-10] ^= 0x01;

  PreKeyWhisperMessage incomingMessage  = new PreKeyWhisperMessage(badMessage);
  SessionCipher        bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1);

  byte[] plaintext = new byte[0];

  try {
    plaintext = bobSessionCipher.decrypt(incomingMessage);
    throw new AssertionError("Decrypt should have failed!");
  } catch (InvalidMessageException e) {
    // good.
  }

  assertTrue(bobStore.containsPreKey(31337));

  plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(goodMessage));

  assertTrue(originalMessage.equals(new String(plaintext)));
  assertTrue(!bobStore.containsPreKey(31337));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:53,代码来源:SessionBuilderTest.java


注:本文中的org.whispersystems.libaxolotl.ecc.ECKeyPair.getPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。