• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ECKeyPair类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: generateLastResortKey

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

  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:SilenceIM,项目名称:Silence,代码行数:20,代码来源:PreKeyUtil.java


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


示例18: setPendingKeyExchange

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
public void setPendingKeyExchange(int sequence,
                                  ECKeyPair ourBaseKey,
                                  ECKeyPair ourRatchetKey,
                                  IdentityKeyPair ourIdentityKey)
{
  PendingKeyExchange structure =
      PendingKeyExchange.newBuilder()
                        .setSequence(sequence)
                        .setLocalBaseKey(ByteString.copyFrom(ourBaseKey.getPublicKey().serialize()))
                        .setLocalBaseKeyPrivate(ByteString.copyFrom(ourBaseKey.getPrivateKey().serialize()))
                        .setLocalRatchetKey(ByteString.copyFrom(ourRatchetKey.getPublicKey().serialize()))
                        .setLocalRatchetKeyPrivate(ByteString.copyFrom(ourRatchetKey.getPrivateKey().serialize()))
                        .setLocalIdentityKey(ByteString.copyFrom(ourIdentityKey.getPublicKey().serialize()))
                        .setLocalIdentityKeyPrivate(ByteString.copyFrom(ourIdentityKey.getPrivateKey().serialize()))
                        .build();

  this.sessionStructure = this.sessionStructure.toBuilder()
                                               .setPendingKeyExchange(structure)
                                               .build();
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:21,代码来源:SessionState.java


示例19: getOrCreateChainKey

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
private ChainKey getOrCreateChainKey(SessionState sessionState, ECPublicKey theirEphemeral)
    throws InvalidMessageException
{
  try {
    if (sessionState.hasReceiverChain(theirEphemeral)) {
      return sessionState.getReceiverChainKey(theirEphemeral);
    } else {
      RootKey                 rootKey         = sessionState.getRootKey();
      ECKeyPair               ourEphemeral    = sessionState.getSenderRatchetKeyPair();
      Pair<RootKey, ChainKey> receiverChain   = rootKey.createChain(theirEphemeral, ourEphemeral);
      ECKeyPair               ourNewEphemeral = Curve.generateKeyPair();
      Pair<RootKey, ChainKey> senderChain     = receiverChain.first().createChain(theirEphemeral, ourNewEphemeral);

      sessionState.setRootKey(senderChain.first());
      sessionState.addReceiverChain(theirEphemeral, receiverChain.second());
      sessionState.setPreviousCounter(Math.max(sessionState.getSenderChainKey().getIndex()-1, 0));
      sessionState.setSenderChain(ourNewEphemeral, senderChain.second());

      return receiverChain.second();
    }
  } catch (InvalidKeyException e) {
    throw new InvalidMessageException(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:25,代码来源:SessionCipher.java


示例20: SymmetricSignalProtocolParameters

import org.whispersystems.libsignal.ecc.ECKeyPair; //导入依赖的package包/类
SymmetricSignalProtocolParameters(ECKeyPair ourBaseKey, ECKeyPair ourRatchetKey,
                                  IdentityKeyPair ourIdentityKey, ECPublicKey theirBaseKey,
                                  ECPublicKey theirRatchetKey, IdentityKey theirIdentityKey)
{
  this.ourBaseKey       = ourBaseKey;
  this.ourRatchetKey    = ourRatchetKey;
  this.ourIdentityKey   = ourIdentityKey;
  this.theirBaseKey     = theirBaseKey;
  this.theirRatchetKey  = theirRatchetKey;
  this.theirIdentityKey = theirIdentityKey;

  if (ourBaseKey == null || ourRatchetKey == null || ourIdentityKey == null ||
      theirBaseKey == null || theirRatchetKey == null || theirIdentityKey == null)
  {
    throw new IllegalArgumentException("Null values!");
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:18,代码来源:SymmetricSignalProtocolParameters.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClusterSettings类代码示例发布时间:2022-05-22
下一篇:
Java FilterChainManager类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap