@Test
  public void testCryptoRecordFromCollectionKeys()
      throws CryptoException, NoCollectionKeysSetException, IOException, ParseException,
          NonObjectJSONException {
    CollectionKeys ck1 = CollectionKeys.generateCollectionKeys();
    assertNotNull(ck1.defaultKeyBundle());
    assertEquals(ck1.keyBundleForCollection("foobar"), ck1.defaultKeyBundle());
    CryptoRecord rec = ck1.asCryptoRecord();
    assertEquals(rec.collection, "crypto");
    assertEquals(rec.guid, "keys");
    JSONArray defaultKey = (JSONArray) rec.payload.get("default");

    assertSame(
        Base64.decodeBase64((String) (defaultKey.get(0))),
        ck1.defaultKeyBundle().getEncryptionKey());
    CollectionKeys ck2 = new CollectionKeys();
    ck2.setKeyPairsFromWBO(rec, null);
    assertSame(
        ck1.defaultKeyBundle().getEncryptionKey(), ck2.defaultKeyBundle().getEncryptionKey());
  }
  @Test
  public void testCreateKeysBundle()
      throws CryptoException, NonObjectJSONException, IOException, ParseException,
          NoCollectionKeysSetException {
    String username = "******";
    String friendlyBase32SyncKey = "basuxv2426eqj7frhvpcwkavdi";

    KeyBundle syncKeyBundle = new KeyBundle(username, friendlyBase32SyncKey);

    CollectionKeys ck = CollectionKeys.generateCollectionKeys();
    CryptoRecord unencrypted = ck.asCryptoRecord();
    unencrypted.keyBundle = syncKeyBundle;
    CryptoRecord encrypted = unencrypted.encrypt();

    CollectionKeys ckDecrypted = new CollectionKeys();
    ckDecrypted.setKeyPairsFromWBO(encrypted, syncKeyBundle);

    // Compare decrypted keys to the keys that were set upon creation
    assertArrayEquals(
        ck.defaultKeyBundle().getEncryptionKey(),
        ckDecrypted.defaultKeyBundle().getEncryptionKey());
    assertArrayEquals(
        ck.defaultKeyBundle().getHMACKey(), ckDecrypted.defaultKeyBundle().getHMACKey());
  }