public static void printKeyset(String type, KeysetHandle keysetHandle) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withOutputStream(outputStream)); log.info("{}: {}", type, new String(outputStream.toByteArray())); } catch (IOException ex) { log.error("Failed to write keyset", ex); } }
/** * 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 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)); } }
/** * 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)); } }
private static void generateEcdsaKeyPair(File publicKeyFile, File privatekeyFile) throws GeneralSecurityException, IOException { KeysetHandle privateKeyHandle = KeysetHandle.generateNew(SIGNATURE_KEY_TEMPLATE); CleartextKeysetHandle.write(privateKeyHandle, BinaryKeysetWriter.withFile(privatekeyFile)); KeysetHandle publicKeyHandle = privateKeyHandle.getPublicKeysetHandle(); CleartextKeysetHandle.write(publicKeyHandle, BinaryKeysetWriter.withFile(publicKeyFile)); } }
ByteArrayOutputStream symmetricKeyOutputStream = new ByteArrayOutputStream(); try { CleartextKeysetHandle.write( symmetricKeyHandle, BinaryKeysetWriter.withOutputStream(symmetricKeyOutputStream)); } catch (IOException e) {
ByteArrayOutputStream symmetricKeyOutputStream = new ByteArrayOutputStream(); try { CleartextKeysetHandle.write( symmetricKeyHandle, BinaryKeysetWriter.withOutputStream(symmetricKeyOutputStream)); } catch (IOException e) {