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

Java SessionCipher类代码示例

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

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



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

示例1: encrypt

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
public OutgoingPushMessage encrypt(SignalProtocolAddress destination, byte[] unpaddedMessage, boolean legacy, boolean silent) {
  SessionCipher        sessionCipher        = new SessionCipher(signalProtocolStore, destination);
  PushTransportDetails transportDetails     = new PushTransportDetails(sessionCipher.getSessionVersion());
  CiphertextMessage    message              = sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage));
  int                  remoteRegistrationId = sessionCipher.getRemoteRegistrationId();
  String               body                 = Base64.encodeBytes(message.serialize());

  int type;

  switch (message.getType()) {
    case CiphertextMessage.PREKEY_TYPE:  type = Type.PREKEY_BUNDLE_VALUE; break;
    case CiphertextMessage.WHISPER_TYPE: type = Type.CIPHERTEXT_VALUE;    break;
    default: throw new AssertionError("Bad type: " + message.getType());
  }

  return new OutgoingPushMessage(type, destination.getDeviceId(), remoteRegistrationId,
                                 legacy ? body : null, legacy ? null : body, silent);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:19,代码来源:SignalServiceCipher.java


示例2: decrypt

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
private byte[] decrypt(SignalServiceEnvelope envelope, byte[] ciphertext)
    throws InvalidVersionException, InvalidMessageException, InvalidKeyException,
           DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException,
           LegacyMessageException, NoSessionException
{
  SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), envelope.getSourceDevice());
  SessionCipher         sessionCipher = new SessionCipher(signalProtocolStore, sourceAddress);

  byte[] paddedMessage;

  if (envelope.isPreKeySignalMessage()) {
    paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext));
  } else if (envelope.isSignalMessage()) {
    paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext));
  } else {
    throw new InvalidMessageException("Unknown type: " + envelope.getType());
  }

  PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
  return transportDetails.getStrippedPaddingMessageBody(paddedMessage);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:22,代码来源:SignalServiceCipher.java


示例3: process

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
/**
 * Build a new session from a {@link org.whispersystems.libsignal.protocol.KeyExchangeMessage}
 * received from a remote client.
 *
 * @param message The received KeyExchangeMessage.
 * @return The KeyExchangeMessage to respond with, or null if no response is necessary.
 * @throws InvalidKeyException if the received KeyExchangeMessage is badly formatted.
 */
public KeyExchangeMessage process(KeyExchangeMessage message)
    throws InvalidKeyException, UntrustedIdentityException, StaleKeyExchangeException
{
  synchronized (SessionCipher.SESSION_LOCK) {
    if (!identityKeyStore.isTrustedIdentity(remoteAddress, message.getIdentityKey())) {
      throw new UntrustedIdentityException(remoteAddress.getName(), message.getIdentityKey());
    }

    KeyExchangeMessage responseMessage = null;

    if (message.isInitiate()) responseMessage = processInitiate(message);
    else                      processResponse(message);

    return responseMessage;
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:25,代码来源:SessionBuilder.java


示例4: decrypt

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
public IncomingTextMessage decrypt(Context context, IncomingTextMessage message)
    throws LegacyMessageException, InvalidMessageException,
           DuplicateMessageException, NoSessionException
{
  try {
    byte[]        decoded       = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
    SignalMessage signalMessage = new SignalMessage(decoded);
    SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(message.getSender(), 1));
    byte[]        padded        = sessionCipher.decrypt(signalMessage);
    byte[]        plaintext     = transportDetails.getStrippedPaddingMessageBody(padded);

    if (message.isEndSession() && "TERMINATE".equals(new String(plaintext))) {
      signalProtocolStore.deleteSession(new SignalProtocolAddress(message.getSender(), 1));
    }

    return message.withMessageBody(new String(plaintext));
  } catch (IOException | IllegalArgumentException | NullPointerException e) {
    throw new InvalidMessageException(e);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:21,代码来源:SmsCipher.java


示例5: encrypt

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
public OutgoingTextMessage encrypt(OutgoingTextMessage message) throws NoSessionException {
  byte[] paddedBody      = transportDetails.getPaddedMessageBody(message.getMessageBody().getBytes());
  String recipientNumber = message.getRecipients().getPrimaryRecipient().getNumber();

  if (!signalProtocolStore.containsSession(new SignalProtocolAddress(recipientNumber, 1))) {
    throw new NoSessionException("No session for: " + recipientNumber);
  }

  SessionCipher     cipher            = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(recipientNumber, 1));
  CiphertextMessage ciphertextMessage = cipher.encrypt(paddedBody);
  String            encodedCiphertext = new String(transportDetails.getEncodedMessage(ciphertextMessage.serialize()));

  if (ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE) {
    return new OutgoingPrekeyBundleMessage(message, encodedCiphertext);
  } else {
    return message.withBody(encodedCiphertext);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:19,代码来源:SmsCipher.java


示例6: encrypt

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
public SendReq encrypt(Context context, SendReq message)
    throws NoSessionException, RecipientFormattingException, UndeliverableMessageException
{
  EncodedStringValue[] encodedRecipient = message.getTo();
  String               recipientString  = encodedRecipient[0].getString();
  byte[]               pduBytes         = new PduComposer(context, message).make();

  if (pduBytes == null) {
    throw new UndeliverableMessageException("PDU composition failed, null payload");
  }

  if (!axolotlStore.containsSession(new SignalProtocolAddress(recipientString, 1))) {
    throw new NoSessionException("No session for: " + recipientString);
  }

  SessionCipher     cipher            = new SessionCipher(axolotlStore, new SignalProtocolAddress(recipientString, 1));
  CiphertextMessage ciphertextMessage = cipher.encrypt(pduBytes);
  byte[]            encryptedPduBytes = textTransport.getEncodedMessage(ciphertextMessage.serialize());

  PduBody body         = new PduBody();
  PduPart part         = new PduPart();
  SendReq encryptedPdu = new SendReq(message.getPduHeaders(), body);

  part.setContentId((System.currentTimeMillis()+"").getBytes());
  part.setContentType(ContentType.TEXT_PLAIN.getBytes());
  part.setName((System.currentTimeMillis()+"").getBytes());
  part.setData(encryptedPduBytes);
  body.addPart(part);
  encryptedPdu.setSubject(new EncodedStringValue(WirePrefix.calculateEncryptedMmsSubject()));
  encryptedPdu.setBody(body);

  return encryptedPdu;
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:34,代码来源:MmsCipher.java


示例7: XmppAxolotlSession

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
public XmppAxolotlSession(Account account, SQLiteAxolotlStore store, SignalProtocolAddress remoteAddress) {
	this.cipher = new SessionCipher(store, remoteAddress);
	this.remoteAddress = remoteAddress;
	this.sqLiteAxolotlStore = store;
	this.account = account;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:7,代码来源:XmppAxolotlSession.java


示例8: XmppAxolotlSession

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
public XmppAxolotlSession(Account account, SQLiteAxolotlStore store, SignalProtocolAddress remoteAddress) {
    this.cipher = new SessionCipher(store, remoteAddress);
    this.remoteAddress = remoteAddress;
    this.sqLiteAxolotlStore = store;
    this.account = account;
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:7,代码来源:XmppAxolotlSession.java


示例9: keyUtil

import org.whispersystems.libsignal.SessionCipher; //导入依赖的package包/类
@Override
public OmemoKeyUtil<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> keyUtil() {
    return new SignalOmemoKeyUtil();
}
 
开发者ID:zom,项目名称:Zom-Android,代码行数:5,代码来源:SignalIOCipherOmemoStore.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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