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


Java KeyHelper类代码示例

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

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

示例1: isTrustedIdentity

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的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


示例2: process

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
/**
 * Initiate a new session by sending an initial KeyExchangeMessage to the recipient.
 *
 * @return the KeyExchangeMessage to deliver.
 */
public KeyExchangeMessage process() {
  synchronized (SessionCipher.SESSION_LOCK) {
    try {
      int             sequence         = KeyHelper.getRandomSequence(65534) + 1;
      int             flags            = KeyExchangeMessage.INITIATE_FLAG;
      ECKeyPair       baseKey          = Curve.generateKeyPair();
      ECKeyPair       ratchetKey       = Curve.generateKeyPair();
      IdentityKeyPair identityKey      = identityKeyStore.getIdentityKeyPair();
      byte[]          baseKeySignature = Curve.calculateSignature(identityKey.getPrivateKey(), baseKey.getPublicKey().serialize());
      SessionRecord   sessionRecord    = sessionStore.loadSession(recipientId, deviceId);

      sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ratchetKey, identityKey);
      sessionStore.storeSession(recipientId, deviceId, sessionRecord);

      return new KeyExchangeMessage(2, sequence, flags, baseKey.getPublicKey(), baseKeySignature,
                                    ratchetKey.getPublicKey(), identityKey.getPublicKey());
    } catch (InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:27,代码来源:SessionBuilder.java


示例3: getLocalRegistrationId

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Override
public int getLocalRegistrationId() {
	try {
		final String registrationIdString = AccountDataTable.getInstance().getString("localRegistrationId");
		if (registrationIdString == null) {
			return KeyHelper.generateRegistrationId(true);
		}
		return Integer.valueOf(registrationIdString);
	} catch (final SQLException e) {
		LOGGER.error("Error while fetching local registration ID. ", e);
		Errors.showError(translate("unexpected_quit"));
		Errors.stopApplication();
		throw new UnreachableCodeException();
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:16,代码来源:IdentityKeyStore.java


示例4: initialize

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
public void initialize(final IdentityKeyPair identityKeyPair, final int signedPreKeyId) {
	try {
		storeSignedPreKey(signedPreKeyId, KeyHelper.generateSignedPreKey(identityKeyPair, signedPreKeyId));
	} catch (final InvalidKeyException e) {
		LOGGER.error("Identity key pair for storage in SignedPreKeyStore was invalid.", e);
		Errors.showError(translate("unexpected_quit"));
		Errors.stopApplication();
		throw new UnreachableCodeException();
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:11,代码来源:SignedPreKeyStore.java


示例5: initialize

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
public List<PreKeyRecord> initialize() {

		final int numberOfKeys = 100;
		final int startingId = (new Random()).nextInt(Medium.MAX_VALUE - numberOfKeys);

		storeLastResortKey(KeyHelper.generateLastResortPreKey());
		final List<PreKeyRecord> list = KeyHelper.generatePreKeys(startingId, numberOfKeys);

		for (final PreKeyRecord key : list) {
			storePreKey(key.getId(), key);
		}

		return list;
	}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:15,代码来源:PreKeyStore.java


示例6: contains_storePreKey

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Test
public void contains_storePreKey() {
	final PreKeyRecord preKey = KeyHelper.generatePreKeys(0, ANY_NUMBER).get(0);
	store.storePreKey(preKey.getId(), preKey);
	assertTrue(store.containsPreKey(preKey.getId()));
	assertFalse(store.containsPreKey(preKey.getId() + 1));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:8,代码来源:AxolotlStoreTest.java


示例7: loadPreKey

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的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());
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:8,代码来源:AxolotlStoreTest.java


示例8: removePreKey

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Test
public void removePreKey() {
	final PreKeyRecord preKey = KeyHelper.generatePreKeys(0, ANY_NUMBER).get(0);
	store.storePreKey(preKey.getId(), preKey);
	store.removePreKey(preKey.getId());
	assertFalse(store.containsPreKey(preKey.getId()));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:8,代码来源:AxolotlStoreTest.java


示例9: signedPreKey

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Test
public void signedPreKey() throws InvalidKeyException, InvalidKeyIdException {
	final Random r = new Random();
	final IdentityKeyPair identityKey = KeyHelper.generateIdentityKeyPair();
	final SignedPreKeyRecord key = KeyHelper.generateSignedPreKey(identityKey, r.nextInt(Integer.MAX_VALUE));

	store.storeSignedPreKey(key.getId(), key);
	assertTrue(store.containsSignedPreKey(key.getId()));
	assertFalse(store.containsSignedPreKey(key.getId() + 1));

	assertArrayEquals(key.serialize(), store.loadSignedPreKey(key.getId()).serialize());
	store.removeSignedPreKey(key.getId());

	assertFalse(store.containsSignedPreKey(key.getId()));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:16,代码来源:AxolotlStoreTest.java


示例10: testBasicEncryptDecrypt

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
public void testBasicEncryptDecrypt()
    throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{
  InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
  InMemorySenderKeyStore bobStore   = new InMemorySenderKeyStore();

  GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
  GroupSessionBuilder bobSessionBuilder   = new GroupSessionBuilder(bobStore);

  GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
  GroupCipher bobGroupCipher   = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");

  byte[]    aliceSenderKey        = KeyHelper.generateSenderKey();
  ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
  int       aliceSenderKeyId      = KeyHelper.generateSenderKeyId();

  SenderKeyDistributionMessage aliceDistributionMessage =
      aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
                                  aliceSenderKey, aliceSenderSigningKey);

  bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);

  byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
  byte[] plaintextFromAlice  = bobGroupCipher.decrypt(ciphertextFromAlice);

  assertTrue(new String(plaintextFromAlice).equals("smert ze smert"));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:28,代码来源:GroupCipherTest.java


示例11: testOutOfOrder

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
public void testOutOfOrder()
    throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{
  InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
  InMemorySenderKeyStore bobStore   = new InMemorySenderKeyStore();

  GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
  GroupSessionBuilder bobSessionBuilder   = new GroupSessionBuilder(bobStore);

  GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
  GroupCipher bobGroupCipher   = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");

  byte[]    aliceSenderKey        = KeyHelper.generateSenderKey();
  ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
  int       aliceSenderKeyId      = KeyHelper.generateSenderKeyId();

  SenderKeyDistributionMessage aliceDistributionMessage =
      aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
                                  aliceSenderKey, aliceSenderSigningKey);

  bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);


  ArrayList<byte[]> ciphertexts = new ArrayList<>(100);

  for (int i=0;i<100;i++) {
    ciphertexts.add(aliceGroupCipher.encrypt("up the punks".getBytes()));
  }

  while (ciphertexts.size() > 0) {
    int    index      = randomInt() % ciphertexts.size();
    byte[] ciphertext = ciphertexts.remove(index);
    byte[] plaintext  = bobGroupCipher.decrypt(ciphertext);

    assertTrue(new String(plaintext).equals("up the punks"));
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:38,代码来源:GroupCipherTest.java


示例12: generateRegistrationId

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
private static int generateRegistrationId() {
	Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl registration ID...");
	return KeyHelper.generateRegistrationId(true);
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:5,代码来源:SQLiteAxolotlStore.java


示例13: handleSmsRegistrationIntent

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
private void handleSmsRegistrationIntent(Intent intent) {
  markAsVerifying(true);

  String       number       = intent.getStringExtra("e164number");
  MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
  int          registrationId = TextSecurePreferences.getLocalRegistrationId(this);

  if (registrationId == 0) {
    registrationId = KeyHelper.generateRegistrationId(false);
    TextSecurePreferences.setLocalRegistrationId(this, registrationId);
  }

  try {
    String password     = Util.getSecret(18);
    String signalingKey = Util.getSecret(52);

    initializeChallengeListener();

    setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number));
    TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(this, number, password);
    accountManager.requestSmsVerificationCode();

    setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
    String challenge = waitForChallenge();
    accountManager.verifyAccount(challenge, signalingKey, true, registrationId);

    handleCommonRegistration(masterSecret, accountManager, number);
    markAsVerified(number, password, signalingKey);

    setState(new RegistrationState(RegistrationState.STATE_COMPLETE, number));
    broadcastComplete(true);
  } catch (ExpectationFailedException efe) {
    Log.w("RegistrationService", efe);
    setState(new RegistrationState(RegistrationState.STATE_MULTI_REGISTERED, number));
    broadcastComplete(false);
  } catch (UnsupportedOperationException uoe) {
    Log.w("RegistrationService", uoe);
    setState(new RegistrationState(RegistrationState.STATE_GCM_UNSUPPORTED, number));
    broadcastComplete(false);
  } catch (AccountVerificationTimeoutException avte) {
    Log.w("RegistrationService", avte);
    setState(new RegistrationState(RegistrationState.STATE_TIMEOUT, number));
    broadcastComplete(false);
  } catch (IOException e) {
    Log.w("RegistrationService", e);
    setState(new RegistrationState(RegistrationState.STATE_NETWORK_ERROR, number));
    broadcastComplete(false);
  } finally {
    shutdownChallengeListener();
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:52,代码来源:RegistrationService.java


示例14: initialize

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
public void initialize() {
	final IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();
	setIdentityKeyPair(identityKeyPair);
	setLocalRegistrationId(KeyHelper.generateRegistrationId(true));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:6,代码来源:IdentityKeyStore.java


示例15: loadPreKeyInvalid

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Test(expected = InvalidKeyIdException.class)
public void loadPreKeyInvalid() throws InvalidKeyIdException {
	final PreKeyRecord preKey = KeyHelper.generatePreKeys(0, ANY_NUMBER).get(0);
	store.storePreKey(42, preKey);
	store.loadPreKey(preKey.getId() + 1);
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:7,代码来源:AxolotlStoreTest.java


示例16: saveIdentity

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Test
public void saveIdentity() {
	final IdentityKey key = KeyHelper.generateIdentityKeyPair().getPublicKey();
	store.saveIdentity("TestName", key);
	assertTrue(store.isTrustedIdentity("TestName", key));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:7,代码来源:AxolotlStoreTest.java


示例17: saveIdentityNameNull

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void saveIdentityNameNull() {
	store.saveIdentity(null, KeyHelper.generateIdentityKeyPair().getPublicKey());
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:5,代码来源:AxolotlStoreTest.java


示例18: testBasicRatchet

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
public void testBasicRatchet()
    throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{
  InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
  InMemorySenderKeyStore bobStore   = new InMemorySenderKeyStore();

  GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
  GroupSessionBuilder bobSessionBuilder   = new GroupSessionBuilder(bobStore);

  GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
  GroupCipher bobGroupCipher   = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");

  byte[]    aliceSenderKey        = KeyHelper.generateSenderKey();
  ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
  int       aliceSenderKeyId      = KeyHelper.generateSenderKeyId();

  SenderKeyDistributionMessage aliceDistributionMessage =
      aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
                                  aliceSenderKey, aliceSenderSigningKey);

  bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);

  byte[] ciphertextFromAlice  = aliceGroupCipher.encrypt("smert ze smert".getBytes());
  byte[] ciphertextFromAlice2 = aliceGroupCipher.encrypt("smert ze smert2".getBytes());
  byte[] ciphertextFromAlice3 = aliceGroupCipher.encrypt("smert ze smert3".getBytes());

  byte[] plaintextFromAlice   = bobGroupCipher.decrypt(ciphertextFromAlice);

  try {
    bobGroupCipher.decrypt(ciphertextFromAlice);
    throw new AssertionError("Should have ratcheted forward!");
  } catch (DuplicateMessageException dme) {
    // good
  }

  byte[] plaintextFromAlice2  = bobGroupCipher.decrypt(ciphertextFromAlice2);
  byte[] plaintextFromAlice3  = bobGroupCipher.decrypt(ciphertextFromAlice3);

  assertTrue(new String(plaintextFromAlice).equals("smert ze smert"));
  assertTrue(new String(plaintextFromAlice2).equals("smert ze smert2"));
  assertTrue(new String(plaintextFromAlice3).equals("smert ze smert3"));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:43,代码来源:GroupCipherTest.java


示例19: handleSmsRegistrationIntent

import org.whispersystems.libaxolotl.util.KeyHelper; //导入依赖的package包/类
private void handleSmsRegistrationIntent(Intent intent) {
  markAsVerifying(true);
  String number = "";
    if(TextSecurePreferences.getRegistrationOptionSelected(getApplicationContext()).equalsIgnoreCase("Phone")){
        number       = intent.getStringExtra("e164number");
    }else if(TextSecurePreferences.getRegistrationOptionSelected(getApplicationContext()).equalsIgnoreCase("Email")){
        number       = intent.getStringExtra("email_address");
    }

  MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
  int          registrationId = TextSecurePreferences.getLocalRegistrationId(this);

  if (registrationId == 0) {
    registrationId = KeyHelper.generateRegistrationId(false);
    TextSecurePreferences.setLocalRegistrationId(this, registrationId);
  }

  try {
    String password     = Util.getSecret(18);
    String signalingKey = Util.getSecret(52);

    initializeChallengeListener();

    setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number));
    TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(this, number, password);
    accountManager.requestSmsVerificationCode();

    setState(new RegistrationState(RegistrationState.STATE_SMS_VERIFICATION, number));
    String challenge = waitForChallenge();
    accountManager.verifyAccount(challenge, signalingKey, true, registrationId);

    handleCommonRegistration(masterSecret, accountManager, number);
    markAsVerified(number, password, signalingKey);

    setState(new RegistrationState(RegistrationState.STATE_COMPLETE, number));
    broadcastComplete(true);
  } catch (ExpectationFailedException efe) {
    Log.w("RegistrationService", efe);
    setState(new RegistrationState(RegistrationState.STATE_MULTI_REGISTERED, number));
    broadcastComplete(false);
  } catch (UnsupportedOperationException uoe) {
    Log.w("RegistrationService", uoe);
    setState(new RegistrationState(RegistrationState.STATE_GCM_UNSUPPORTED, number));
    broadcastComplete(false);
  } catch (AccountVerificationTimeoutException avte) {
    Log.w("RegistrationService", avte);
    setState(new RegistrationState(RegistrationState.STATE_TIMEOUT, number));
    broadcastComplete(false);
  } catch (IOException e) {
    Log.w("RegistrationService", e);
    setState(new RegistrationState(RegistrationState.STATE_NETWORK_ERROR, number));
    broadcastComplete(false);
  }finally {
    shutdownChallengeListener();
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:57,代码来源:RegistrationService.java



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