Package com.google.k2crypto

Examples of com.google.k2crypto.Key


   * @throws StoreException if there is an unexpected error loading.
   */
  protected void checkLoad(ReadableDriver driver, Key expected)
      throws StoreException {
    assertFalse(driver.isEmpty());
    Key loaded = driver.load();
    assertEquals(
        expected.buildData().build().toByteString(),
        loaded.buildData().build().toByteString());   
  }
View Full Code Here


   
    // Deserialize bytes of loaded key
    ExtensionRegistry registry =
        context.getKeyVersionRegistry().getProtoExtensions();
    try {
      return new Key(context, KeyData.parseFrom(bytes, registry));
    } catch (IOException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.READ_ERROR, ex);
    } catch (InvalidKeyDataException ex) {
      throw new StoreIOException(
View Full Code Here

  private Key readKey(File file, ExtensionRegistry registry)
      throws StoreIOException {
    FileInputStream in = null;
    try {
      in = new FileInputStream(file);
      return new Key(context, KeyData.parseFrom(in, registry));
    } catch (IOException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.READ_ERROR, ex);
    } catch (InvalidKeyDataException ex) {
      throw new StoreIOException(
View Full Code Here

    KeyData data = memSpace.load(address);
    if (data == null) {
      return null;
    }
    try {
      return new Key(context, data);
    } catch (InvalidKeyDataException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.DESERIALIZATION_ERROR, ex);
    } catch (UnregisteredKeyVersionException ex) {
      throw new StoreIOException(
View Full Code Here

   * @see WritableDriver#erase()
   */
  public boolean erase() {
    ++eraseCalls;
    checkOpen();
    Key erasedKey = storedKey;
    storedKey = null;
    storedKeyWrapper = null;
    return erasedKey != null;
  }
View Full Code Here

  public static class WriteOnly extends MockDriver
      implements WritableDriver, WrappingDriver {
   
    @Override
    public Key load() throws StoreException {
      Key key = super.load(); // just for accounting
      fail("Load should not be called on write-only drivers.");
      return key;
    }
View Full Code Here

    context = new K2Context();
    normalDriver = new InstalledDriver(context, MockDriver.Normal.class);
   
    // TODO(darylseah): We need a proper way to create keys for testing.
    //                  The current approach is fragile and WILL break later.
    saveKey = new Key();
    wrapKeyA = new Key();
    wrapKeyB = new Key();
  }
View Full Code Here

      assertEquals(store, expected.getStore());
    }
    assertEquals(3, driver.loadCalls);
   
    // Read encrypted key
    Key key = store.wrapWith(wrapKeyB).load();
    assertEquals(4, driver.wrapWithCalls);
    assertEquals(wrapKeyB, driver.wrapKey);
    assertTrue(store.isWrapping());
    assertEquals(4, driver.isWrappingCalls);     
    assertEquals(4, driver.loadCalls);     
View Full Code Here

      // Something wrong with a storage driver
      throw ex;
    }
   
    // Create a key
    Key original;
    try {
      original = new Key(new AESKeyVersion.Builder().build());
    } catch (BuilderException ex) {
      // Problem building key
      throw ex;
    }
   
    // Quickly save it (the native driver recognizes file:// addresses)
    storage.save(NATIVE_STORE.toURI(), original);
   
    // Quickly load it back
    Key loaded = storage.load(NATIVE_STORE.toURI());
    assert(original.buildData().build().equals(loaded.buildData().build()));
   
    // Use Store API for more elaborate operations
    Store store = null;
    try {
      // Open a SQLite database store
      store = storage.open(
          "sqlite:" + SQLITE_DATABASE.toURI().getRawPath() + "#samekey");
     
      // Save previously loaded key
      store.save(loaded);
     
      // Check store is not empty and load key back
      if (!store.isEmpty()) {
        Key sameKey = store.load();
        assert(loaded.buildData().build().equals(sameKey.buildData().build()));
      }
     
    } finally {
      // Close store
      if (store != null) {
View Full Code Here

TOP

Related Classes of com.google.k2crypto.Key

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.