예제 #1
0
  @Test
  public void testFindFirstAboveThresholdPublicKey() throws GeneralSecurityException {
    IEncryptionManager encryptionManager = new EncryptionManager();
    PublicKey publicKey1 = encryptionManager.generateKeyPair().getPublic();
    PublicKey publicKey2 = encryptionManager.generateKeyPair().getPublic();

    List<PublicKey> publicKeys = new ArrayList<PublicKey>();
    publicKeys.add(publicKey1);
    publicKeys.add(publicKey1);
    publicKeys.add(publicKey1);
    publicKeys.add(publicKey2);

    PublicKey result = new ThresholdChooser<PublicKey>().findFirstAboveThreshold(publicKeys, 3);

    assertEquals(publicKey1, result);
  }
예제 #2
0
  /**
   * @param encryptionManager IEncryptionManager used to construct a SecretKey object.
   * @param privateProfileDocument PrivateProfileDocument containing given friend's SecretKey.
   * @param friendName Friend whose SecretKey is to be found.
   * @return A SecretKey object if one is found for the given friend's name, null otherwise.
   * @throws GeneralSecurityException
   */
  public static SecretKey findSecretKey(
      IEncryptionManager encryptionManager,
      PrivateProfileDocument privateProfileDocument,
      String friendName)
      throws GeneralSecurityException {

    int indexOfKey = findIndexOfFriendPublicProfileKey(privateProfileDocument, friendName);
    if (indexOfKey >= 0) {
      FriendKeyMapping[] friendKeys =
          privateProfileDocument.getPrivateProfile().getFriendKeyList().getFriendKeyArray();
      byte[] keyBytes = friendKeys[indexOfKey].getSharedProfileKey().getKeyByteArray();
      return encryptionManager.generateSecretKey(keyBytes);
    } else {
      return null;
    }
  }