本文整理汇总了Java中org.whispersystems.libaxolotl.InvalidKeyIdException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidKeyIdException类的具体用法?Java InvalidKeyIdException怎么用?Java InvalidKeyIdException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidKeyIdException类属于org.whispersystems.libaxolotl包,在下文中一共展示了InvalidKeyIdException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public IncomingEncryptedMessage decrypt(Context context, IncomingPreKeyBundleMessage message)
throws InvalidVersionException, InvalidMessageException, DuplicateMessageException,
UntrustedIdentityException, LegacyMessageException
{
try {
Recipients recipients = RecipientFactory.getRecipientsFromString(context, message.getSender(), false);
byte[] decoded = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
PreKeyWhisperMessage preKeyMessage = new PreKeyWhisperMessage(decoded);
SessionCipher sessionCipher = new SessionCipher(axolotlStore, recipients.getPrimaryRecipient().getRecipientId(), 1);
byte[] padded = sessionCipher.decrypt(preKeyMessage);
byte[] plaintext = transportDetails.getStrippedPaddingMessageBody(padded);
return new IncomingEncryptedMessage(message, new String(plaintext));
} catch (RecipientFormattingException | IOException | InvalidKeyException | InvalidKeyIdException e) {
throw new InvalidMessageException(e);
}
}
示例2: generateLastResortKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context, MasterSecret masterSecret) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(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 = Curve25519.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);
preKeyStore.storePreKey(Medium.MAX_VALUE, record);
return record;
}
示例3: decrypt
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public TextSecureMessage decrypt(TextSecureEnvelope envelope)
throws InvalidVersionException, InvalidMessageException, InvalidKeyException,
DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException,
LegacyMessageException, NoSessionException
{
try {
byte[] paddedMessage;
if (envelope.isPreKeyWhisperMessage()) {
paddedMessage = sessionCipher.decrypt(new PreKeyWhisperMessage(envelope.getMessage()));
} else if (envelope.isWhisperMessage()) {
paddedMessage = sessionCipher.decrypt(new WhisperMessage(envelope.getMessage()));
} else if (envelope.isPlaintext()) {
paddedMessage = envelope.getMessage();
} else {
throw new InvalidMessageException("Unknown type: " + envelope.getType());
}
PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
PushMessageContent content = PushMessageContent.parseFrom(transportDetails.getStrippedPaddingMessageBody(paddedMessage));
return createTextSecureMessage(envelope, content);
} catch (InvalidProtocolBufferException e) {
throw new InvalidMessageException(e);
}
}
示例4: loadSignedPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
@Override
public SignedPreKeyRecord loadSignedPreKey(final int signedPreKeyId) throws InvalidKeyIdException {
try {
final SignedPreKeyRecord record = SignedPreKeyTable.getInstance().loadKey(signedPreKeyId);
if (record == null) {
LOGGER.debug("Tried to fetch SignedPreKeyRecord for the invalid key ID [{}].", signedPreKeyId);
throw new InvalidKeyIdException("Key id " + signedPreKeyId + " has no associated PreKeyRecord.");
}
return SignedPreKeyTable.getInstance().loadKey(signedPreKeyId);
} catch (final SQLException e) {
LOGGER.error("Signed pre key could not be fetched from database.", e);
Errors.showError(translate("unexpected_quit"));
Errors.stopApplication();
throw new UnreachableCodeException();
}
}
示例5: decrypt
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public TextSecureSMPMessage decrypt(TextSecureEnvelope envelope) throws InvalidVersionException,
InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException, LegacyMessageException, NoSessionException {
try {
AxolotlAddress e = new AxolotlAddress(envelope.getSource(), envelope.getSourceDevice());
SessionCipher sessionCipher = new SessionCipher(this.axolotlStore, e);
byte[] paddedMessage;
if(envelope.isPreKeyWhisperMessage()) {
paddedMessage = sessionCipher.decrypt(new PreKeyWhisperMessage(envelope.getMessage()));
} else {
if(!envelope.isWhisperMessage()) {
throw new InvalidMessageException("Unknown type: " + envelope.getType());
}
paddedMessage = sessionCipher.decrypt(new WhisperMessage(envelope.getMessage()));
}
PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
PushMessageProtos.PushMessageContent content = PushMessageProtos.PushMessageContent.parseFrom(transportDetails.getStrippedPaddingMessageBody(paddedMessage));
return this.createTextSecureSMPMessage(envelope, content);
} catch (InvalidProtocolBufferException var7) {
throw new InvalidMessageException(var7);
}
}
示例6: generateLastResortKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context, MasterSecret masterSecret) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(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;
}
示例7: encrypt
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public byte[] encrypt(byte[] paddedPlaintext) throws NoSessionException {
synchronized (LOCK) {
try {
SenderKeyRecord record = senderKeyStore.loadSenderKey(senderKeyId);
SenderKeyState senderKeyState = record.getSenderKeyState();
SenderMessageKey senderKey = senderKeyState.getSenderChainKey().getSenderMessageKey();
byte[] ciphertext = getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(),
senderKey.getIteration(),
ciphertext,
senderKeyState.getSigningKeyPrivate());
senderKeyState.setSenderChainKey(senderKeyState.getSenderChainKey().getNext());
senderKeyStore.storeSenderKey(senderKeyId, record);
return senderKeyMessage.serialize();
} catch (InvalidKeyIdException e) {
throw new NoSessionException(e);
}
}
}
示例8: decrypt
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
public byte[] decrypt(byte[] senderKeyMessageBytes)
throws LegacyMessageException, InvalidMessageException, DuplicateMessageException
{
synchronized (LOCK) {
try {
SenderKeyRecord record = senderKeyStore.loadSenderKey(senderKeyId);
SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyMessageBytes);
SenderKeyState senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
SenderMessageKey senderKey = getSenderKey(senderKeyState, senderKeyMessage.getIteration());
byte[] plaintext = getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
senderKeyStore.storeSenderKey(senderKeyId, record);
return plaintext;
} catch (org.whispersystems.libaxolotl.InvalidKeyException | InvalidKeyIdException e) {
throw new InvalidMessageException(e);
}
}
}
示例9: loadPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
/**
* Load a local PreKeyRecord.
*
* @param preKeyId the ID of the local PreKeyRecord.
* @return the corresponding PreKeyRecord.
* @throws InvalidKeyIdException when there is no corresponding PreKeyRecord.
*/
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
PreKeyRecord record = mXmppConnectionService.databaseBackend.loadPreKey(account, preKeyId);
if (record == null) {
throw new InvalidKeyIdException("No such PreKeyRecord: " + preKeyId);
}
return record;
}
示例10: loadSignedPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
/**
* Load a local SignedPreKeyRecord.
*
* @param signedPreKeyId the ID of the local SignedPreKeyRecord.
* @return the corresponding SignedPreKeyRecord.
* @throws InvalidKeyIdException when there is no corresponding SignedPreKeyRecord.
*/
@Override
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
SignedPreKeyRecord record = mXmppConnectionService.databaseBackend.loadSignedPreKey(account, signedPreKeyId);
if (record == null) {
throw new InvalidKeyIdException("No such SignedPreKeyRecord: " + signedPreKeyId);
}
return record;
}
示例11: loadPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
synchronized (FILE_LOCK) {
try {
return new PreKeyRecord(loadSerializedRecord(getPreKeyFile(preKeyId)));
} catch (IOException | InvalidMessageException e) {
Log.w(TAG, e);
throw new InvalidKeyIdException(e);
}
}
}
示例12: loadSignedPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
@Override
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
synchronized (FILE_LOCK) {
try {
return new SignedPreKeyRecord(loadSerializedRecord(getSignedPreKeyFile(signedPreKeyId)));
} catch (IOException | InvalidMessageException e) {
Log.w(TAG, e);
throw new InvalidKeyIdException(e);
}
}
}
示例13: onRun
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
try {
SignedPreKeyStore signedPreKeyStore = signedPreKeyStoreFactory.create(masterSecret);
SignedPreKeyEntity currentSignedPreKey = accountManager.getSignedPreKey();
if (currentSignedPreKey == null) return;
SignedPreKeyRecord currentRecord = signedPreKeyStore.loadSignedPreKey(currentSignedPreKey.getKeyId());
List<SignedPreKeyRecord> allRecords = signedPreKeyStore.loadSignedPreKeys();
LinkedList<SignedPreKeyRecord> oldRecords = removeRecordFrom(currentRecord, allRecords);
Collections.sort(oldRecords, new SignedPreKeySorter());
Log.w(TAG, "Old signed prekey record count: " + oldRecords.size());
boolean foundAgedRecord = false;
for (SignedPreKeyRecord oldRecord : oldRecords) {
long archiveDuration = System.currentTimeMillis() - oldRecord.getTimestamp();
if (archiveDuration >= TimeUnit.DAYS.toMillis(ARCHIVE_AGE_DAYS)) {
if (!foundAgedRecord) {
foundAgedRecord = true;
} else {
Log.w(TAG, "Removing signed prekey record: " + oldRecord.getId() + " with timestamp: " + oldRecord.getTimestamp());
signedPreKeyStore.removeSignedPreKey(oldRecord.getId());
}
}
}
} catch (InvalidKeyIdException e) {
Log.w(TAG, e);
}
}
示例14: loadPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
@Override
public PreKeyRecord loadPreKey(final int preKeyId) throws InvalidKeyIdException {
try {
final PreKeyRecord record = PreKeyTable.getInstance().getKey(preKeyId);
if (record == null) {
throw new InvalidKeyIdException("Key id " + preKeyId + " has no associated PreKeyRecord.");
}
return PreKeyTable.getInstance().getKey(preKeyId);
} catch (final SQLException e) {
LOGGER.error("PreKey could not be fetched from database.", e);
Errors.showError(translate("unexpected_quit"));
Errors.stopApplication();
throw new UnreachableCodeException();
}
}
示例15: loadPreKey
import org.whispersystems.libaxolotl.InvalidKeyIdException; //导入依赖的package包/类
@Test
public void loadPreKey() throws InvalidKeyIdException {
final PreKeyRecord preKey = KeyHelper.generatePreKeys(0, ANY_NUMBER).get(0);
store.storePreKey(preKey.getId(), preKey);
final PreKeyRecord newKey = store.loadPreKey(preKey.getId());
assertArrayEquals(preKey.serialize(), newKey.serialize());
}