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


Java ECKeyPair类代码示例

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


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

示例1: generatePreKeys

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
private List<PreKeyRecord> generatePreKeys() {
    List<PreKeyRecord> records = new LinkedList<>();

    int preKeyIdOffset = localIdentity.getPreKeyIdOffset();

    for (int i = 0; i < PREKEY_BATCH_SIZE; i++) {
        int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        signalProtocolStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    preKeyIdOffset = (preKeyIdOffset + PREKEY_BATCH_SIZE + 1) % Medium.MAX_VALUE;
    localIdentity.setPreKeyIdOffset(preKeyIdOffset);
    this.storage.getLocalIdentityStore().saveLocalIdentity(localIdentity);

    return records;
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:21,代码来源:Manager.java

示例2: getOrGenerateLastResortPreKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
private PreKeyRecord getOrGenerateLastResortPreKey() {
    if (signalProtocolStore.containsPreKey(Medium.MAX_VALUE)) {
        try {
            return signalProtocolStore.loadPreKey(Medium.MAX_VALUE);
        } catch (InvalidKeyIdException e) {
            signalProtocolStore.removePreKey(Medium.MAX_VALUE);
        }
    }

    ECKeyPair keyPair = Curve.generateKeyPair();
    PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

    signalProtocolStore.storePreKey(Medium.MAX_VALUE, record);

    return record;
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:17,代码来源:Manager.java

示例3: generateSignedPreKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
private SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair) {
    try {
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
        int nextSignedPreKeyId = localIdentity.getNextSignedPreKeyId();
        SignedPreKeyRecord record = new SignedPreKeyRecord(nextSignedPreKeyId, System.currentTimeMillis(), keyPair, signature);

        signalProtocolStore.storeSignedPreKey(nextSignedPreKeyId, record);
        nextSignedPreKeyId = (nextSignedPreKeyId + 1) % Medium.MAX_VALUE;

        localIdentity.setNextSignedPreKeyId(nextSignedPreKeyId);
        this.storage.getLocalIdentityStore().saveLocalIdentity(localIdentity);

        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:19,代码来源:Manager.java

示例4: generatePreKeys

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context) {
  PreKeyStore        preKeyStore    = new TextSecurePreKeyStore(context);
  List<PreKeyRecord> records        = new LinkedList<>();
  int                preKeyIdOffset = getNextPreKeyId(context);

  for (int i=0;i<BATCH_SIZE;i++) {
    int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
    ECKeyPair    keyPair  = Curve.generateKeyPair();
    PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

    preKeyStore.storePreKey(preKeyId, record);
    records.add(record);
  }

  setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
  return records;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:PreKeyUtil.java

示例5: generateSignedPreKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static SignedPreKeyRecord generateSignedPreKey(Context context, IdentityKeyPair identityKeyPair, boolean active)
{
  try {
    SignedPreKeyStore  signedPreKeyStore = new TextSecurePreKeyStore(context);
    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);

    if (active) {
      setActiveSignedPreKeyId(context, signedPreKeyId);
    }

    return record;
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:22,代码来源:PreKeyUtil.java

示例6: generateLastResortKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context) {
  PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);

  if (preKeyStore.containsPreKey(Medium.MAX_VALUE)) {
    try {
      return preKeyStore.loadPreKey(Medium.MAX_VALUE);
    } catch (InvalidKeyIdException e) {
      Log.w("PreKeyUtil", e);
      preKeyStore.removePreKey(Medium.MAX_VALUE);
    }
  }

  ECKeyPair    keyPair = Curve.generateKeyPair();
  PreKeyRecord record  = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

  preKeyStore.storePreKey(Medium.MAX_VALUE, record);

  return record;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:20,代码来源:PreKeyUtil.java

示例7: 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

示例8: encrypt

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public byte[] encrypt(ProvisionMessage message) throws InvalidKeyException {
  ECKeyPair ourKeyPair    = Curve.generateKeyPair();
  byte[]    sharedSecret  = Curve.calculateAgreement(theirPublicKey, ourKeyPair.getPrivateKey());
  byte[]    derivedSecret = new HKDFv3().deriveSecrets(sharedSecret, "TextSecure Provisioning Message".getBytes(), 64);
  byte[][]  parts         = Util.split(derivedSecret, 32, 32);

  byte[] version    = {0x01};
  byte[] ciphertext = getCiphertext(parts[0], message.toByteArray());
  byte[] mac        = getMac(parts[1], Util.join(version, ciphertext));
  byte[] body       = Util.join(version, ciphertext, mac);

  return ProvisionEnvelope.newBuilder()
                          .setPublicKey(ByteString.copyFrom(ourKeyPair.getPublicKey().serialize()))
                          .setBody(ByteString.copyFrom(body))
                          .build()
                          .toByteArray();
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:18,代码来源:ProvisioningCipher.java

示例9: generatePreKeys

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context) {
    PreKeyStore preKeyStore    = new SignalPreKeyStore();
    List<PreKeyRecord> records        = new LinkedList<>();
    int                preKeyIdOffset = getNextPreKeyId(context);

    for (int i=0;i<BATCH_SIZE;i++) {
        int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair    keyPair  = Curve.generateKeyPair();
        PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

        preKeyStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
    return records;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:18,代码来源:PreKeyUtil.java

示例10: generateSignedPreKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static SignedPreKeyRecord generateSignedPreKey(Context context, IdentityKeyPair identityKeyPair, boolean active)
{
    try {
        SignedPreKeyStore signedPreKeyStore = new SignalPreKeyStore();
        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);

        if (active) {
            setActiveSignedPreKeyId(context, signedPreKeyId);
        }

        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:22,代码来源:PreKeyUtil.java

示例11: generateLastResortKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context) {
    PreKeyStore preKeyStore = new SignalPreKeyStore();

    if (preKeyStore.containsPreKey(Medium.MAX_VALUE)) {
        try {
            return preKeyStore.loadPreKey(Medium.MAX_VALUE);
        } catch (InvalidKeyIdException e) {
            LogUtil.w("PreKeyUtil", e.toString());
            preKeyStore.removePreKey(Medium.MAX_VALUE);
        }
    }

    ECKeyPair    keyPair = Curve.generateKeyPair();
    PreKeyRecord record  = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

    preKeyStore.storePreKey(Medium.MAX_VALUE, record);

    return record;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:20,代码来源:PreKeyUtil.java

示例12: generatePreKeys

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
private List<PreKeyRecord> generatePreKeys() {
    List<PreKeyRecord> records = new LinkedList<>();

    for (int i = 0; i < PREKEY_BATCH_SIZE; i++) {
        int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        signalProtocolStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    preKeyIdOffset = (preKeyIdOffset + PREKEY_BATCH_SIZE + 1) % Medium.MAX_VALUE;
    save();

    return records;
}
 
开发者ID:AsamK,项目名称:signal-cli,代码行数:18,代码来源:Manager.java

示例13: 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

示例14: generatePreKeys

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context, MasterSecret masterSecret) {
  PreKeyStore        preKeyStore    = new SilencePreKeyStore(context, masterSecret);
  List<PreKeyRecord> records        = new LinkedList<>();
  int                preKeyIdOffset = getNextPreKeyId(context);

  for (int i=0;i<BATCH_SIZE;i++) {
    int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
    ECKeyPair    keyPair  = Curve.generateKeyPair();
    PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

    preKeyStore.storePreKey(preKeyId, record);
    records.add(record);
  }

  setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
  return records;
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:18,代码来源:PreKeyUtil.java

示例15: generateSignedPreKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public static SignedPreKeyRecord generateSignedPreKey(Context context, MasterSecret masterSecret,
                                                      IdentityKeyPair identityKeyPair)
{
  try {
    SignedPreKeyStore  signedPreKeyStore = new SilencePreKeyStore(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);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:19,代码来源:PreKeyUtil.java


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