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


Java InvalidKeyException类代码示例

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


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

示例1: generateSignedPreKey

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的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

示例2: encryptBytes

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的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

示例3: addDevice

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
public void addDevice(String deviceIdentifier,
                      ECPublicKey deviceKey,
                      IdentityKeyPair identityKeyPair,
                      String code)
    throws InvalidKeyException, IOException
{
  ProvisioningCipher cipher  = new ProvisioningCipher(deviceKey);
  ProvisionMessage   message = ProvisionMessage.newBuilder()
                                               .setIdentityKeyPublic(ByteString.copyFrom(identityKeyPair.getPublicKey().serialize()))
                                               .setIdentityKeyPrivate(ByteString.copyFrom(identityKeyPair.getPrivateKey().serialize()))
                                               .setNumber(user)
                                               .setProvisioningCode(code)
                                               .build();

  byte[] ciphertext = cipher.encrypt(message);
  this.pushServiceSocket.sendProvisioningMessage(deviceIdentifier, ciphertext);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:18,代码来源:SignalServiceAccountManager.java

示例4: decrypt

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的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

示例5: encrypt

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的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

示例6: getIdentity

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
public Optional<IdentityRecord> getIdentity(long recipientId) {
  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  Cursor         cursor   = null;

  try {
    cursor = database.query(TABLE_NAME, null, RECIPIENT + " = ?",
                            new String[] {recipientId + ""}, null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
      return Optional.of(getIdentityRecord(cursor));
    }
  } catch (InvalidKeyException | IOException e) {
    throw new AssertionError(e);
  } finally {
    if (cursor != null) cursor.close();
  }

  return Optional.absent();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:20,代码来源:IdentityDatabase.java

示例7: onRun

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  try {
    if (!TextSecurePreferences.isMultiDevice(context)) {
      Log.w(TAG, "Not multi device...");
      return;
    }

    if (destination == null) {
      Log.w(TAG, "No destination...");
      return;
    }

    String                        canonicalDestination = Util.canonicalizeNumber(context, destination);
    VerifiedMessage.VerifiedState verifiedState        = getVerifiedState(verifiedStatus);
    SignalServiceMessageSender    messageSender        = messageSenderFactory.create();
    VerifiedMessage               verifiedMessage      = new VerifiedMessage(canonicalDestination, new IdentityKey(identityKey, 0), verifiedState, timestamp);

    messageSender.sendMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
  } catch (InvalidNumberException | InvalidKeyException e) {
    throw new IOException(e);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:24,代码来源:MultiDeviceVerifiedUpdateJob.java

示例8: handleIndividualRecipient

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
private void handleIndividualRecipient(Recipient recipient)
    throws IOException, InvalidKeyException, InvalidNumberException
{
  String               number  = Util.canonicalizeNumber(context, recipient.getNumber());
  SignalServiceProfile profile = retrieveProfile(number);

  if (TextUtils.isEmpty(profile.getIdentityKey())) {
    Log.w(TAG, "Identity key is missing on profile!");
    return;
  }

  IdentityKey identityKey = new IdentityKey(Base64.decode(profile.getIdentityKey()), 0);

  if (!DatabaseFactory.getIdentityDatabase(context)
                      .getIdentity(recipient.getRecipientId())
                      .isPresent())
  {
    Log.w(TAG, "Still first use...");
    return;
  }

  IdentityUtil.saveIdentity(context, number, identityKey);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:24,代码来源:RetrieveProfileJob.java

示例9: loadIdentityKeys

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
public Set<IdentityKey> loadIdentityKeys(Account account, String name, FingerprintStatus status) {
	Set<IdentityKey> identityKeys = new HashSet<>();
	Cursor cursor = getIdentityKeyCursor(account, name, false);

	while (cursor.moveToNext()) {
		if (status != null && !FingerprintStatus.fromCursor(cursor).equals(status)) {
			continue;
		}
		try {
			String key = cursor.getString(cursor.getColumnIndex(SQLiteAxolotlStore.KEY));
			if (key != null) {
				identityKeys.add(new IdentityKey(Base64.decode(key, Base64.DEFAULT), 0));
			} else {
				Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Missing key (possibly preverified) in database for account" + account.getJid().toBareJid() + ", address: " + name);
			}
		} catch (InvalidKeyException e) {
			Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Encountered invalid IdentityKey in database for account" + account.getJid().toBareJid() + ", address: " + name);
		}
	}
	cursor.close();

	return identityKeys;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:24,代码来源:DatabaseBackend.java

示例10: finishConnectAsSecondary

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
/**
 * Blocking call. Call this directly after {@code startConnectAsSecondary()} and this method will wait
 * for the master device accepting this device.
 * @param deviceName a name for this device (not the user agent)
 * @param supportsSms whether this device can receive and send SMS
 * @throws IOException
 * @throws TimeoutException
 */
public void finishConnectAsSecondary(String deviceName, boolean supportsSms) throws IOException, TimeoutException {
	if(accountManager == null) {
		throw new IllegalStateException("Cannot finish: No connection started!");
	} else if(isRegistered()) {
		throw new IllegalStateException("Already registered!");
	}
	try {
		NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(tempIdentity,
				store.getSignalingKey(), supportsSms, true, store.getLocalRegistrationId(), deviceName);
		store.setDeviceId(ret.getDeviceId());
		store.setIdentityKeyPair(ret.getIdentity());
	} catch (InvalidKeyException e) {
		throw new RuntimeException("This can not happen - theoretically", e);
	}
	store.setLastResortPreKey(KeyHelper.generateLastResortPreKey());
	checkPreKeys(-1);
	save();
}
 
开发者ID:Turakar,项目名称:signal4j,代码行数:27,代码来源:SignalService.java

示例11: tryFetchLatestMessage

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
@WorkerThread
private IncomingMessage tryFetchLatestMessage() throws TimeoutException {
    if (this.messagePipe == null) {
        this.messagePipe = messageReceiver.createMessagePipe();
    }

    try {
        final SignalServiceEnvelope envelope = messagePipe.read(INCOMING_MESSAGE_TIMEOUT, TimeUnit.SECONDS);
        return decryptIncomingSignalServiceEnvelope(envelope);
    } catch (final TimeoutException ex) {
        throw new TimeoutException(ex.getMessage());
    } catch (final IllegalStateException | InvalidKeyException | InvalidKeyIdException | DuplicateMessageException | InvalidVersionException | LegacyMessageException | InvalidMessageException | NoSessionException | org.whispersystems.libsignal.UntrustedIdentityException | IOException e) {
        LogUtil.exception(getClass(), "Error while fetching latest message", e);
    }
    return null;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:17,代码来源:SofaMessageReceiver.java

示例12: handleIncomingSofaMessage

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
private IncomingMessage handleIncomingSofaMessage(final SignalServiceEnvelope envelope) throws InvalidVersionException, InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, org.whispersystems.libsignal.UntrustedIdentityException, LegacyMessageException, NoSessionException {
    final SignalServiceAddress localAddress = new SignalServiceAddress(this.wallet.getOwnerAddress());
    final SignalServiceCipher cipher = new SignalServiceCipher(localAddress, this.protocolStore);
    final SignalServiceContent content = cipher.decrypt(envelope);
    final String messageSource = envelope.getSource();

    if (isUserBlocked(messageSource)) {
        LogUtil.i(getClass(), "A blocked user is trying to send a message");
        return null;
    }

    if (content.getDataMessage().isPresent()) {
        final SignalServiceDataMessage dataMessage = content.getDataMessage().get();
        if (dataMessage.isGroupUpdate()) return taskGroupUpdate.run(messageSource, dataMessage);
        else return taskHandleMessage.run(messageSource, dataMessage);
    }
    return null;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:19,代码来源:SofaMessageReceiver.java

示例13: registerKeys

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
public Completable registerKeys(final ProtocolStore protocolStore) {
    try {
        return registerKeys(
                protocolStore.getIdentityKeyPair().getPublicKey(),
                protocolStore.getLastResortKey(),
                protocolStore.getPassword(),
                protocolStore.getLocalRegistrationId(),
                protocolStore.getSignalingKey(),
                protocolStore.getSignedPreKey(),
                protocolStore.getPreKeys()
        );
    } catch (final IOException | InvalidKeyIdException | InvalidKeyException ex) {
        LogUtil.e(getClass(), "ERROR!" + ex.toString());
        return Completable.error(ex);
    }
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:17,代码来源:ChatService.java

示例14: generateSignedPreKey

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的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

示例15: finishRegistration

import org.whispersystems.libsignal.InvalidKeyException; //导入依赖的package包/类
public void finishRegistration(String deviceName, Consumer<Void> callback) {
	executor.submit(new Runnable() {
		@Override
		public void run() {
			String temporarySignalingKey = SecretUtil.getSecret(52);
			int temporaryRegistrationId = KeyHelper.generateRegistrationId(false);
			try {
				NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(temporaryIdentity,
						temporarySignalingKey, false, true, temporaryRegistrationId, deviceName);
				logger.debug("Got response from master device for provisioning");
				Main.getInstance().getStore().getUserStore().createNewIdentity(ret.getNumber(), ret.getDeviceId(),
						temporaryPassword, temporaryRegistrationId, temporarySignalingKey, temporaryIdentity);
				callback.accept(null);
			} catch (TimeoutException | IOException | InvalidKeyException e) {
				e.printStackTrace();
				throw new RuntimeException("Could not finish device registration!", e);
			}

		}
	});
}
 
开发者ID:Turakar,项目名称:Signal-JDesktop,代码行数:22,代码来源:SignalAccountHelper.java


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