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


Java ECKeyPair.getPublicKey方法代码示例

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


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

示例1: encryptBytes

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

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

    return Util.combine(publicKeyBytes, encryptedBodyBytes);
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:AsymmetricMasterCipher.java

示例2: process

import org.whispersystems.libsignal.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(remoteAddress);

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

      return new KeyExchangeMessage(CiphertextMessage.CURRENT_VERSION,
                                    sequence, flags, baseKey.getPublicKey(), baseKeySignature,
                                    ratchetKey.getPublicKey(), identityKey.getPublicKey());
    } catch (InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:28,代码来源:SessionBuilder.java

示例3: encryptBody

import org.whispersystems.libsignal.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:SilenceIM,项目名称:Silence,代码行数:18,代码来源:AsymmetricMasterCipher.java

示例4: testMatchingFingerprints

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testMatchingFingerprints() throws FingerprintVersionMismatchException, FingerprintIdentifierMismatchException, FingerprintParsingException {
  ECKeyPair aliceKeyPair = Curve.generateKeyPair();
  ECKeyPair bobKeyPair   = Curve.generateKeyPair();

  IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey());
  IdentityKey bobIdentityKey   = new IdentityKey(bobKeyPair.getPublicKey());

  NumericFingerprintGenerator generator        = new NumericFingerprintGenerator(1024);
  Fingerprint                 aliceFingerprint = generator.createFor("+14152222222", aliceIdentityKey,
                                                                     "+14153333333", bobIdentityKey);

  Fingerprint bobFingerprint = generator.createFor("+14153333333", bobIdentityKey,
                                                   "+14152222222", aliceIdentityKey);

  assertEquals(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
               bobFingerprint.getDisplayableFingerprint().getDisplayText());

  assertTrue(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized()));
  assertTrue(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized()));

  assertEquals(aliceFingerprint.getDisplayableFingerprint().getDisplayText().length(), 60);
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:23,代码来源:NumericFingerprintGeneratorTest.java

示例5: testMismatchingFingerprints

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testMismatchingFingerprints() throws FingerprintVersionMismatchException, FingerprintIdentifierMismatchException, FingerprintParsingException {
  ECKeyPair aliceKeyPair = Curve.generateKeyPair();
  ECKeyPair bobKeyPair   = Curve.generateKeyPair();
  ECKeyPair mitmKeyPair  = Curve.generateKeyPair();

  IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey());
  IdentityKey bobIdentityKey   = new IdentityKey(bobKeyPair.getPublicKey());
  IdentityKey mitmIdentityKey  = new IdentityKey(mitmKeyPair.getPublicKey());

  NumericFingerprintGenerator generator        = new NumericFingerprintGenerator(1024);
  Fingerprint                 aliceFingerprint = generator.createFor("+14152222222", aliceIdentityKey,
                                                                     "+14153333333", mitmIdentityKey);

  Fingerprint bobFingerprint = generator.createFor("+14153333333", bobIdentityKey,
                                                   "+14152222222", aliceIdentityKey);

  assertNotSame(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
                bobFingerprint.getDisplayableFingerprint().getDisplayText());

  assertFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized()));
  assertFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized()));
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:23,代码来源:NumericFingerprintGeneratorTest.java

示例6: testMismatchingIdentifiers

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testMismatchingIdentifiers() throws FingerprintVersionMismatchException, FingerprintParsingException {
  ECKeyPair aliceKeyPair = Curve.generateKeyPair();
  ECKeyPair bobKeyPair   = Curve.generateKeyPair();

  IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey());
  IdentityKey bobIdentityKey   = new IdentityKey(bobKeyPair.getPublicKey());

  NumericFingerprintGenerator generator        = new NumericFingerprintGenerator(1024);
  Fingerprint                 aliceFingerprint = generator.createFor("+141512222222", aliceIdentityKey,
                                                                     "+14153333333", bobIdentityKey);

  Fingerprint bobFingerprint = generator.createFor("+14153333333", bobIdentityKey,
                                                   "+14152222222", aliceIdentityKey);

  assertNotSame(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
                bobFingerprint.getDisplayableFingerprint().getDisplayText());

  assertFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized()));
  assertFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized()));
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:21,代码来源:NumericFingerprintGeneratorTest.java

示例7: testBasicPreKeyV2

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testBasicPreKeyV2()
    throws InvalidKeyException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, UntrustedIdentityException, NoSessionException {
  SignalProtocolStore aliceStore          = new TestInMemorySignalProtocolStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS);

  SignalProtocolStore bobStore      = new TestInMemorySignalProtocolStore();
  ECKeyPair    bobPreKeyPair = Curve.generateKeyPair();
  PreKeyBundle bobPreKey     = new PreKeyBundle(bobStore.getLocalRegistrationId(), 1,
                                                31337, bobPreKeyPair.getPublicKey(),
                                                0, null, null,
                                                bobStore.getIdentityKeyPair().getPublicKey());

  try {
    aliceSessionBuilder.process(bobPreKey);
    throw new AssertionError("Should fail with missing unsigned prekey!");
  } catch (InvalidKeyException e) {
    // Good!
    return;
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:21,代码来源:SessionBuilderTest.java

示例8: createAlicePreKeyBundle

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
private PreKeyBundle createAlicePreKeyBundle(SignalProtocolStore 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:signalapp,项目名称:libsignal-protocol-java,代码行数:17,代码来源:SimultaneousInitiateTests.java

示例9: createBobPreKeyBundle

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
private PreKeyBundle createBobPreKeyBundle(SignalProtocolStore 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:signalapp,项目名称:libsignal-protocol-java,代码行数:17,代码来源:SimultaneousInitiateTests.java

示例10: generateIdentityKeys

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

示例11: generateAsymmetricMasterSecret

import org.whispersystems.libsignal.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:XecureIT,项目名称:PeSanKita-android,代码行数:12,代码来源:MasterSecretUtil.java

示例12: generateIdentityKeys

import org.whispersystems.libsignal.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:SilenceIM,项目名称:Silence,代码行数:11,代码来源:IdentityKeyUtil.java

示例13: generateCurve25519IdentityKeys

import org.whispersystems.libsignal.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:SilenceIM,项目名称:Silence,代码行数:10,代码来源:IdentityKeyUtil.java

示例14: initializeSessionsV3

import org.whispersystems.libsignal.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();

  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);
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:41,代码来源:SessionCipherTest.java

示例15: testRepeatBundleMessageV2

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入方法依赖的package包/类
public void testRepeatBundleMessageV2() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, NoSessionException {
  SignalProtocolStore aliceStore          = new TestInMemorySignalProtocolStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS);

  SignalProtocolStore bobStore = new TestInMemorySignalProtocolStore();

  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(),
                                            0, null, null,
                                            bobStore.getIdentityKeyPair().getPublicKey());

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

  try {
    aliceSessionBuilder.process(bobPreKey);
    throw new AssertionError("Should fail with missing signed prekey!");
  } catch (InvalidKeyException e) {
    // Good!
    return;
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:28,代码来源:SessionBuilderTest.java


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