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


Java IdentityKey类代码示例

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


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

示例1: publishBundles

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
                               final Set<PreKeyRecord> preKeyRecords, final int deviceId) {
	final Element item = new Element("item");
	final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
	final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
	signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
	ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
	signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(),Base64.DEFAULT));
	final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
	signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(),Base64.DEFAULT));
	final Element identityKeyElement = bundle.addChild("identityKey");
	identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));

	final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
	for(PreKeyRecord preKeyRecord:preKeyRecords) {
		final Element prekey = prekeys.addChild("preKeyPublic");
		prekey.setAttribute("preKeyId", preKeyRecord.getId());
		prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT));
	}

	return publish(AxolotlService.PEP_BUNDLES+":"+deviceId, item);
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:23,代码来源:IqGenerator.java

示例2: loadIdentityKeys

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

	while (cursor.moveToNext()) {
		if (trust != null &&
				cursor.getInt(cursor.getColumnIndex(SQLiteAxolotlStore.TRUSTED))
						!= trust.getCode()) {
			continue;
		}
		try {
			identityKeys.add(new IdentityKey(Base64.decode(cursor.getString(cursor.getColumnIndex(SQLiteAxolotlStore.KEY)), Base64.DEFAULT), 0));
		} 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:xavierle,项目名称:messengerxmpp,代码行数:21,代码来源:DatabaseBackend.java

示例3: getIdentityKey

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
private IdentityKey getIdentityKey(IncomingKeyExchangeMessage message)
    throws InvalidKeyException, InvalidVersionException,
           InvalidMessageException, LegacyMessageException
{
  try {
    if (message.isIdentityUpdate()) {
      return new IdentityKey(Base64.decodeWithoutPadding(message.getMessageBody()), 0);
    } else if (message.isPreKeyBundle()) {
      boolean isPush = getIntent().getBooleanExtra("is_push", false);

      if (isPush) return new PreKeyWhisperMessage(Base64.decode(message.getMessageBody())).getIdentityKey();
      else        return new PreKeyWhisperMessage(Base64.decodeWithoutPadding(message.getMessageBody())).getIdentityKey();
    } else {
      return new KeyExchangeMessage(Base64.decodeWithoutPadding(message.getMessageBody())).getIdentityKey();
    }
  } catch (IOException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:20,代码来源:ReceiveKeyActivity.java

示例4: saveIdentity

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public void saveIdentity(MasterSecret masterSecret, long recipientId, IdentityKey identityKey)
{
  SQLiteDatabase database   = databaseHelper.getWritableDatabase();
  MasterCipher masterCipher = new MasterCipher(masterSecret);
  String identityKeyString  = Base64.encodeBytes(identityKey.serialize());
  String macString          = Base64.encodeBytes(masterCipher.getMacFor(recipientId +
                                                                            identityKeyString));

  ContentValues contentValues = new ContentValues();
  contentValues.put(RECIPIENT, recipientId);
  contentValues.put(IDENTITY_KEY, identityKeyString);
  contentValues.put(MAC, macString);

  database.replace(TABLE_NAME, null, contentValues);

  context.getContentResolver().notifyChange(CHANGE_URI, null);
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:18,代码来源:IdentityDatabase.java

示例5: initializeRemoteIdentityKey

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
private void initializeRemoteIdentityKey() {
  IdentityKeyParcelable identityKeyParcelable = getIntent().getParcelableExtra("remote_identity");
  IdentityKey           identityKey           = null;

  if (identityKeyParcelable != null) {
    identityKey = identityKeyParcelable.get();
  }

  if (identityKey == null) {
    identityKey = getRemoteIdentityKey(masterSecret, recipient);
  }

  if (identityKey == null) {
    remoteIdentityFingerprint.setText(R.string.VerifyIdentityActivity_recipient_has_no_identity_key);
  } else {
    remoteIdentityFingerprint.setText(identityKey.getFingerprint());
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:19,代码来源:VerifyIdentityActivity.java

示例6: getIdentityKeyPair

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public static IdentityKeyPair getIdentityKeyPair(Context context,
                                                 MasterSecret masterSecret)
{
  if (!hasIdentityKey(context))
    return null;

  try {
    MasterCipher masterCipher = new MasterCipher(masterSecret);
    IdentityKey  publicKey    = getIdentityKey(context);
    ECPrivateKey privateKey   = masterCipher.decryptKey(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_DJB_PREF)));

    return new IdentityKeyPair(publicKey, privateKey);
  } catch (IOException | InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:17,代码来源:IdentityKeyUtil.java

示例7: registerPreKeys

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public void registerPreKeys(IdentityKey identityKey,
                            PreKeyRecord lastResortKey,
                            SignedPreKeyRecord signedPreKey,
                            List<PreKeyRecord> records)
    throws IOException
{
  List<PreKeyEntity> entities = new LinkedList<>();

  for (PreKeyRecord record : records) {
    PreKeyEntity entity = new PreKeyEntity(record.getId(),
                                           record.getKeyPair().getPublicKey());

    entities.add(entity);
  }

  PreKeyEntity lastResortEntity = new PreKeyEntity(lastResortKey.getId(),
                                                   lastResortKey.getKeyPair().getPublicKey());

  SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
                                                                 signedPreKey.getKeyPair().getPublicKey(),
                                                                 signedPreKey.getSignature());

  makeRequest(String.format(PREKEY_PATH, ""), "PUT",
              PreKeyState.toJson(new PreKeyState(entities, lastResortEntity,
                                                 signedPreKeyEntity, identityKey)));
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:27,代码来源:PushServiceSocket.java

示例8: isTrustedIdentity

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
@Override
public boolean isTrustedIdentity(final String name, final IdentityKey identityKey) {
	IdentityKey storedKey;
	try {
		storedKey = IdentityKeyTable.getInstance().getIdentity(name);
		if (storedKey != null) {
			return storedKey.equals(identityKey);
		}
		return true;

	} catch (final SQLException e) {
		LOGGER.error("Error while looking up identity trust. ", e);
		Errors.showError(translate("databaseError"));
		Errors.stopApplication();
		throw new UnreachableCodeException();
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:18,代码来源:IdentityKeyStore.java

示例9: getIdentity

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public IdentityKey getIdentity(final String name) throws SQLException {
	final String query = "SELECT identity_key FROM identity_keystore WHERE user_id = ?";

	try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) {

		stmt.setString(1, name);
		final ResultSet result = stmt.executeQuery();
		if (result.first()) {
			try {
				return new IdentityKey(result.getBytes(1), 0);
			} catch (final InvalidKeyException e) {
				throw new SQLException(
						"IdentityKeyTable: Value of identity_key for user_id [" + name + "] is invalid.", e);
			}
		} else {
			return null;
		}
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:20,代码来源:IdentityKeyTable.java

示例10: isTrustedIdentity

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
@Test
public void isTrustedIdentity() throws InterruptedException {
	final IdentityKey key = KeyHelper.generateIdentityKeyPair().getPublicKey();
	Thread.sleep(1000);
	final IdentityKey wrongKey = KeyHelper.generateIdentityKeyPair().getPublicKey();
	assertNotEquals(key, wrongKey);

	// Case: Correct Name and Key
	store.saveIdentity("TestName", key);
	assertTrue(store.isTrustedIdentity("TestName", key));

	// Case: Unknown Key (remember: TextSecure uses Trust On First Use!)
	assertTrue(store.isTrustedIdentity("UnseenName", key));

	// Case: Wrong Key
	assertFalse(store.isTrustedIdentity("TestName", wrongKey));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:18,代码来源:AxolotlStoreTest.java

示例11: setMismatchedIdentity

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public void setMismatchedIdentity(long messageId, final long recipientId, final IdentityKey identityKey) {
  List<IdentityKeyMismatch> items = new ArrayList<IdentityKeyMismatch>() {{
    add(new IdentityKeyMismatch(recipientId, identityKey));
  }};

  IdentityKeyMismatchList document = new IdentityKeyMismatchList(items);

  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.beginTransaction();

  try {
    setDocument(database, messageId, MISMATCHED_IDENTITIES, document);

    database.setTransactionSuccessful();
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
  } finally {
    database.endTransaction();
  }
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:21,代码来源:MessagingDatabase.java

示例12: WhisperMessage

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
public WhisperMessage(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 = WhisperProtos.WhisperMessage.newBuilder()
                                 .setRatchetKey(ByteString.copyFrom(senderRatchetKey.serialize()))
                                 .setCounter(counter)
                                 .setPreviousCounter(previousCounter)
                                 .setCiphertext(ByteString.copyFrom(ciphertext))
                                 .build().toByteArray();

  byte[] mac     = getMac(messageVersion, 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:Securecom,项目名称:Securecom-Messaging,代码行数:24,代码来源:WhisperMessage.java

示例13: getMac

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

    if (messageVersion >= 3) {
      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:Securecom,项目名称:Securecom-Messaging,代码行数:21,代码来源:WhisperMessage.java

示例14: AliceAxolotlParameters

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
private AliceAxolotlParameters(IdentityKeyPair ourIdentityKey, ECKeyPair ourBaseKey,
                               IdentityKey theirIdentityKey, ECPublicKey theirSignedPreKey,
                               ECPublicKey theirRatchetKey, Optional<ECPublicKey> theirOneTimePreKey)
{
  this.ourIdentityKey     = ourIdentityKey;
  this.ourBaseKey         = ourBaseKey;
  this.theirIdentityKey   = theirIdentityKey;
  this.theirSignedPreKey  = theirSignedPreKey;
  this.theirRatchetKey    = theirRatchetKey;
  this.theirOneTimePreKey = theirOneTimePreKey;

  if (ourIdentityKey == null || ourBaseKey == null || theirIdentityKey == null ||
      theirSignedPreKey == null || theirRatchetKey == null || theirOneTimePreKey == null)
  {
    throw new IllegalArgumentException("Null values!");
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:18,代码来源:AliceAxolotlParameters.java

示例15: SymmetricAxolotlParameters

import org.whispersystems.libaxolotl.IdentityKey; //导入依赖的package包/类
SymmetricAxolotlParameters(ECKeyPair ourBaseKey, ECKeyPair ourRatchetKey,
                           IdentityKeyPair ourIdentityKey, ECPublicKey theirBaseKey,
                           ECPublicKey theirRatchetKey, IdentityKey theirIdentityKey)
{
  this.ourBaseKey       = ourBaseKey;
  this.ourRatchetKey    = ourRatchetKey;
  this.ourIdentityKey   = ourIdentityKey;
  this.theirBaseKey     = theirBaseKey;
  this.theirRatchetKey  = theirRatchetKey;
  this.theirIdentityKey = theirIdentityKey;

  if (ourBaseKey == null || ourRatchetKey == null || ourIdentityKey == null ||
      theirBaseKey == null || theirRatchetKey == null || theirIdentityKey == null)
  {
    throw new IllegalArgumentException("Null values!");
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:18,代码来源:SymmetricAxolotlParameters.java


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