/** * Static method to create a JsonKeysetWriter that writes to a file path. * * <p>This method only works on Android API level 26 or newer. */ public static KeysetWriter withPath(Path path) throws IOException { return withFile(path.toFile()); }
/** Static method to create a JsonKeysetWriter that writes to a file path. */ public static KeysetWriter withPath(String path) throws IOException { return withFile(new File(path)); }
/** * Stores the private keyset in the projects resources/keysets directory if it does not exist yet. * * @throws IOException Failure during saving * @throws GeneralSecurityException Failure during keyset generation */ private void generateAndStorePrivateKey() throws IOException, GeneralSecurityException { KeysetHandle keysetHandle = KeysetHandle.generateNew(HybridKeyTemplates.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM); File keysetFile = new File(PRIVATE_KEYSET_FILENAME); if (!keysetFile.exists()) { CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withFile(keysetFile)); } }
/** * Stores the public keyset in the projects resources/keysets directory if it does not exist yet. * * @throws IOException Failure during saving * @throws GeneralSecurityException Failure during keyset generation */ private void generateAndStorePublicKey(KeysetHandle privateKeysetHandle) throws IOException, GeneralSecurityException { KeysetHandle keysetHandle = privateKeysetHandle.getPublicKeysetHandle(); File keysetFile = new File(PUBLIC_KEYSET_FILENAME); if (!keysetFile.exists()) { CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withFile(keysetFile)); } }
/** * Stores the keyset in the projects resources/keysets directory if it does not exist yet. * * @throws IOException Failure during saving * @throws GeneralSecurityException Failure during keyset generation */ private void generateAndStoreKey() throws IOException, GeneralSecurityException { KeysetHandle keysetHandle = KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM); File keysetFile = new File(KEYSET_FILENAME); if (!keysetFile.exists()) { CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withFile(keysetFile)); } }