當前位置: 首頁>>代碼示例>>Java>>正文


Java SessionState.setSenderChain方法代碼示例

本文整理匯總了Java中org.whispersystems.libaxolotl.state.SessionState.setSenderChain方法的典型用法代碼示例。如果您正苦於以下問題:Java SessionState.setSenderChain方法的具體用法?Java SessionState.setSenderChain怎麽用?Java SessionState.setSenderChain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.whispersystems.libaxolotl.state.SessionState的用法示例。


在下文中一共展示了SessionState.setSenderChain方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getOrCreateChainKey

import org.whispersystems.libaxolotl.state.SessionState; //導入方法依賴的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:Securecom,項目名稱:Securecom-Messaging,代碼行數:25,代碼來源:SessionCipher.java

示例2: initializeSession

import org.whispersystems.libaxolotl.state.SessionState; //導入方法依賴的package包/類
public static void initializeSession(SessionState sessionState,
                                     int sessionVersion,
                                     AliceAxolotlParameters parameters)
    throws InvalidKeyException
{
  try {
    sessionState.setSessionVersion(sessionVersion);
    sessionState.setRemoteIdentityKey(parameters.getTheirIdentityKey());
    sessionState.setLocalIdentityKey(parameters.getOurIdentityKey().getPublicKey());

    ECKeyPair             sendingRatchetKey = Curve.generateKeyPair();
    ByteArrayOutputStream secrets           = new ByteArrayOutputStream();

    if (sessionVersion >= 3) {
      secrets.write(getDiscontinuityBytes());
    }

    secrets.write(Curve.calculateAgreement(parameters.getTheirSignedPreKey(),
                                           parameters.getOurIdentityKey().getPrivateKey()));
    secrets.write(Curve.calculateAgreement(parameters.getTheirIdentityKey().getPublicKey(),
                                           parameters.getOurBaseKey().getPrivateKey()));
    secrets.write(Curve.calculateAgreement(parameters.getTheirSignedPreKey(),
                                           parameters.getOurBaseKey().getPrivateKey()));

    if (sessionVersion >= 3 & parameters.getTheirOneTimePreKey().isPresent()) {
      secrets.write(Curve.calculateAgreement(parameters.getTheirOneTimePreKey().get(),
                                             parameters.getOurBaseKey().getPrivateKey()));
    }

    DerivedKeys             derivedKeys  = calculateDerivedKeys(sessionVersion, secrets.toByteArray());
    Pair<RootKey, ChainKey> sendingChain = derivedKeys.getRootKey().createChain(parameters.getTheirRatchetKey(), sendingRatchetKey);

    sessionState.addReceiverChain(parameters.getTheirRatchetKey(), derivedKeys.getChainKey());
    sessionState.setSenderChain(sendingRatchetKey, sendingChain.second());
    sessionState.setRootKey(sendingChain.first());
  } catch (IOException e) {
    throw new AssertionError(e);
  }
}
 
開發者ID:Securecom,項目名稱:Securecom-Messaging,代碼行數:40,代碼來源:RatchetingSession.java


注:本文中的org.whispersystems.libaxolotl.state.SessionState.setSenderChain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。