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


Java ByteUtil类代码示例

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


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

示例1: ScannableFingerprint

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
ScannableFingerprint(byte[] localFingerprintData, byte[] remoteFingerprintData)
{
  LogicalFingerprint localFingerprint = LogicalFingerprint.newBuilder()
                                                          .setContent(ByteString.copyFrom(ByteUtil.trim(localFingerprintData, 32)))
                                                          .build();

  LogicalFingerprint remoteFingerprint = LogicalFingerprint.newBuilder()
                                                           .setContent(ByteString.copyFrom(ByteUtil.trim(remoteFingerprintData, 32)))
                                                           .build();

  this.fingerprints = CombinedFingerprints.newBuilder()
                                          .setVersion(VERSION)
                                          .setLocalFingerprint(localFingerprint)
                                          .setRemoteFingerprint(remoteFingerprint)
                                          .build();
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:17,代码来源:ScannableFingerprint.java

示例2: getFingerprint

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
private byte[] getFingerprint(int iterations, String stableIdentifier, List<IdentityKey> unsortedIdentityKeys) {
  try {
    MessageDigest digest    = MessageDigest.getInstance("SHA-512");
    byte[]        publicKey = getLogicalKeyBytes(unsortedIdentityKeys);
    byte[]        hash      = ByteUtil.combine(ByteUtil.shortToByteArray(FINGERPRINT_VERSION),
                                               publicKey, stableIdentifier.getBytes());

    for (int i=0;i<iterations;i++) {
      digest.update(hash);
      hash = digest.digest(publicKey);
    }

    return hash;
  } catch (NoSuchAlgorithmException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:18,代码来源:NumericFingerprintGenerator.java

示例3: SenderKeyMessage

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public SenderKeyMessage(int keyId, int iteration, byte[] ciphertext, ECPrivateKey signatureKey) {
  byte[] version = {ByteUtil.intsToByteHighAndLow(CURRENT_VERSION, CURRENT_VERSION)};
  byte[] message = SignalProtos.SenderKeyMessage.newBuilder()
                                                .setId(keyId)
                                                .setIteration(iteration)
                                                .setCiphertext(ByteString.copyFrom(ciphertext))
                                                .build().toByteArray();

  byte[] signature = getSignature(signatureKey, ByteUtil.combine(version, message));

  this.serialized       = ByteUtil.combine(version, message, signature);
  this.messageVersion   = CURRENT_VERSION;
  this.keyId            = keyId;
  this.iteration        = iteration;
  this.ciphertext       = ciphertext;
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:17,代码来源:SenderKeyMessage.java

示例4: SignalMessage

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public SignalMessage(int messageVersion, SecretKeySpec macKey, ECPublicKey senderRatchetKey,
                     int counter, int previousCounter, byte[] ciphertext,
                     IdentityKey senderIdentityKey,
                     IdentityKey receiverIdentityKey)
{
  byte[] version = {ByteUtil.intsToByteHighAndLow(messageVersion, CURRENT_VERSION)};
  byte[] message = SignalProtos.SignalMessage.newBuilder()
                                             .setRatchetKey(ByteString.copyFrom(senderRatchetKey.serialize()))
                                             .setCounter(counter)
                                             .setPreviousCounter(previousCounter)
                                             .setCiphertext(ByteString.copyFrom(ciphertext))
                                             .build().toByteArray();

  byte[] mac     = getMac(senderIdentityKey, receiverIdentityKey, macKey, ByteUtil.combine(version, message));

  this.serialized       = ByteUtil.combine(version, message, mac);
  this.senderRatchetKey = senderRatchetKey;
  this.counter          = counter;
  this.previousCounter  = previousCounter;
  this.ciphertext       = ciphertext;
  this.messageVersion   = messageVersion;
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:23,代码来源:SignalMessage.java

示例5: getMac

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
private byte[] getMac(IdentityKey senderIdentityKey,
                      IdentityKey receiverIdentityKey,
                      SecretKeySpec macKey, byte[] serialized)
{
  try {
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(macKey);

    mac.update(senderIdentityKey.getPublicKey().serialize());
    mac.update(receiverIdentityKey.getPublicKey().serialize());

    byte[] fullMac = mac.doFinal(serialized);
    return ByteUtil.trim(fullMac, MAC_LENGTH);
  } catch (NoSuchAlgorithmException | java.security.InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:18,代码来源:SignalMessage.java

示例6: DeviceConsistencyCommitment

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public DeviceConsistencyCommitment(int generation, List<IdentityKey> identityKeys) {
  try {
    ArrayList<IdentityKey> sortedIdentityKeys = new ArrayList<>(identityKeys);
    Collections.sort(sortedIdentityKeys, new IdentityKeyComparator());

    MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
    messageDigest.update(VERSION.getBytes());
    messageDigest.update(ByteUtil.intToByteArray(generation));

    for (IdentityKey commitment : sortedIdentityKeys) {
      messageDigest.update(commitment.getPublicKey().serialize());
    }

    this.generation = generation;
    this.serialized = messageDigest.digest();
  } catch (NoSuchAlgorithmException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:20,代码来源:DeviceConsistencyCommitment.java

示例7: generateFor

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public static String generateFor(DeviceConsistencyCommitment commitment,
                                 List<DeviceConsistencySignature> signatures)
{
  try {
    ArrayList<DeviceConsistencySignature> sortedSignatures = new ArrayList<>(signatures);
    Collections.sort(sortedSignatures, new SignatureComparator());

    MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
    messageDigest.update(ByteUtil.shortToByteArray(CODE_VERSION));
    messageDigest.update(commitment.toByteArray());

    for (DeviceConsistencySignature signature : sortedSignatures) {
      messageDigest.update(signature.getVrfOutput());
    }

    byte[] hash = messageDigest.digest();

    String digits = getEncodedChunk(hash, 0) + getEncodedChunk(hash, 5);
    return digits.substring(0, 6);

  } catch (NoSuchAlgorithmException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:25,代码来源:DeviceConsistencyCodeGenerator.java

示例8: KeyExchangeMessage

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public KeyExchangeMessage(byte[] serialized)
    throws InvalidMessageException, InvalidVersionException, LegacyMessageException
{
  try {
    byte[][] parts        = ByteUtil.split(serialized, 1, serialized.length - 1);
    this.version          = ByteUtil.highBitsToInt(parts[0][0]);
    this.supportedVersion = ByteUtil.lowBitsToInt(parts[0][0]);

    if (this.version < CiphertextMessage.CURRENT_VERSION) {
      throw new LegacyMessageException("Unsupported legacy version: " + this.version);
    }

    if (this.version > CiphertextMessage.CURRENT_VERSION) {
      throw new InvalidVersionException("Unknown version: " + this.version);
    }

    SignalProtos.KeyExchangeMessage message = SignalProtos.KeyExchangeMessage.parseFrom(parts[1]);

    if (!message.hasId()           || !message.hasBaseKey()     ||
        !message.hasRatchetKey()   || !message.hasIdentityKey() ||
        !message.hasBaseKeySignature())
    {
      throw new InvalidMessageException("Some required fields missing!");
    }

    this.sequence         = message.getId() >> 5;
    this.flags            = message.getId() & 0x1f;
    this.serialized       = serialized;
    this.baseKey          = Curve.decodePoint(message.getBaseKey().toByteArray(), 0);
    this.baseKeySignature = message.getBaseKeySignature().toByteArray();
    this.ratchetKey       = Curve.decodePoint(message.getRatchetKey().toByteArray(), 0);
    this.identityKey      = new IdentityKey(message.getIdentityKey().toByteArray(), 0);
  } catch (InvalidKeyException | IOException e) {
    throw new InvalidMessageException(e);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:37,代码来源:KeyExchangeMessage.java

示例9: SenderMessageKey

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public SenderMessageKey(int iteration, byte[] seed) {
  byte[] derivative = new HKDFv3().deriveSecrets(seed, "WhisperGroup".getBytes(), 48);
  byte[][] parts    = ByteUtil.split(derivative, 16, 32);

  this.iteration = iteration;
  this.seed      = seed;
  this.iv        = parts[0];
  this.cipherKey = parts[1];
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:10,代码来源:SenderMessageKey.java

示例10: SenderKeyDistributionMessage

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public SenderKeyDistributionMessage(int id, int iteration, byte[] chainKey, ECPublicKey signatureKey) {
  byte[] version = {ByteUtil.intsToByteHighAndLow(CURRENT_VERSION, CURRENT_VERSION)};
  byte[] protobuf = SignalProtos.SenderKeyDistributionMessage.newBuilder()
                                                             .setId(id)
                                                             .setIteration(iteration)
                                                             .setChainKey(ByteString.copyFrom(chainKey))
                                                             .setSigningKey(ByteString.copyFrom(signatureKey.serialize()))
                                                             .build().toByteArray();

  this.id           = id;
  this.iteration    = iteration;
  this.chainKey     = chainKey;
  this.signatureKey = signatureKey;
  this.serialized   = ByteUtil.combine(version, protobuf);
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:16,代码来源:SenderKeyDistributionMessage.java

示例11: PreKeySignalMessage

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public PreKeySignalMessage(byte[] serialized)
    throws InvalidMessageException, InvalidVersionException
{
  try {
    this.version = ByteUtil.highBitsToInt(serialized[0]);

    if (this.version > CiphertextMessage.CURRENT_VERSION) {
      throw new InvalidVersionException("Unknown version: " + this.version);
    }

    if (this.version < CiphertextMessage.CURRENT_VERSION) {
      throw new LegacyMessageException("Legacy version: " + this.version);
    }

    SignalProtos.PreKeySignalMessage preKeyWhisperMessage
        = SignalProtos.PreKeySignalMessage.parseFrom(ByteString.copyFrom(serialized, 1,
                                                                         serialized.length-1));

    if (!preKeyWhisperMessage.hasSignedPreKeyId()  ||
        !preKeyWhisperMessage.hasBaseKey()         ||
        !preKeyWhisperMessage.hasIdentityKey()     ||
        !preKeyWhisperMessage.hasMessage())
    {
      throw new InvalidMessageException("Incomplete message.");
    }

    this.serialized     = serialized;
    this.registrationId = preKeyWhisperMessage.getRegistrationId();
    this.preKeyId       = preKeyWhisperMessage.hasPreKeyId() ? Optional.of(preKeyWhisperMessage.getPreKeyId()) : Optional.<Integer>absent();
    this.signedPreKeyId = preKeyWhisperMessage.hasSignedPreKeyId() ? preKeyWhisperMessage.getSignedPreKeyId() : -1;
    this.baseKey        = Curve.decodePoint(preKeyWhisperMessage.getBaseKey().toByteArray(), 0);
    this.identityKey    = new IdentityKey(Curve.decodePoint(preKeyWhisperMessage.getIdentityKey().toByteArray(), 0));
    this.message        = new SignalMessage(preKeyWhisperMessage.getMessage().toByteArray());
  } catch (InvalidProtocolBufferException | InvalidKeyException | LegacyMessageException e) {
    throw new InvalidMessageException(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:38,代码来源:PreKeySignalMessage.java

示例12: verifySignature

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public void verifySignature(ECPublicKey signatureKey)
    throws InvalidMessageException
{
  try {
    byte[][] parts    = ByteUtil.split(serialized, serialized.length - SIGNATURE_LENGTH, SIGNATURE_LENGTH);

    if (!Curve.verifySignature(signatureKey, parts[0], parts[1])) {
      throw new InvalidMessageException("Invalid signature!");
    }

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

示例13: verifyMac

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public void verifyMac(IdentityKey senderIdentityKey, IdentityKey receiverIdentityKey, SecretKeySpec macKey)
    throws InvalidMessageException
{
  byte[][] parts    = ByteUtil.split(serialized, serialized.length - MAC_LENGTH, MAC_LENGTH);
  byte[]   ourMac   = getMac(senderIdentityKey, receiverIdentityKey, macKey, parts[0]);
  byte[]   theirMac = parts[1];

  if (!MessageDigest.isEqual(ourMac, theirMac)) {
    throw new InvalidMessageException("Bad Mac!");
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:12,代码来源:SignalMessage.java

示例14: DerivedMessageSecrets

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
public DerivedMessageSecrets(byte[] okm) {
  try {
    byte[][] keys = ByteUtil.split(okm, CIPHER_KEY_LENGTH, MAC_KEY_LENGTH, IV_LENGTH);

    this.cipherKey = new SecretKeySpec(keys[0], "AES");
    this.macKey    = new SecretKeySpec(keys[1], "HmacSHA256");
    this.iv        = new IvParameterSpec(keys[2]);
  } catch (ParseException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:12,代码来源:DerivedMessageSecrets.java

示例15: calculateDerivedKeys

import org.whispersystems.libsignal.util.ByteUtil; //导入依赖的package包/类
private static DerivedKeys calculateDerivedKeys(byte[] masterSecret) {
  HKDF     kdf                = new HKDFv3();
  byte[]   derivedSecretBytes = kdf.deriveSecrets(masterSecret, "WhisperText".getBytes(), 64);
  byte[][] derivedSecrets     = ByteUtil.split(derivedSecretBytes, 32, 32);

  return new DerivedKeys(new RootKey(kdf, derivedSecrets[0]),
                         new ChainKey(kdf, derivedSecrets[1], 0));
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:9,代码来源:RatchetingSession.java


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