private KeysetHandle loadPrivateKey() throws IOException, GeneralSecurityException { return CleartextKeysetHandle.read(JsonKeysetReader.withFile(new File(PRIVATE_KEYSET_FILENAME))); }
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); } }
private KeysetHandle loadPublicKey() throws IOException, GeneralSecurityException { return CleartextKeysetHandle.read(JsonKeysetReader.withFile(new File(PUBLIC_KEYSET_FILENAME))); }
/** * 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)); } }
private KeysetHandle loadKey() throws IOException, GeneralSecurityException { return CleartextKeysetHandle.read(JsonKeysetReader.withFile(new File(KEYSET_FILENAME))); }
/** * 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)); } }
/** * Constructs a new RSA-ECDSA EncrypterManager. * * <p>Please note that the {@link InputStream} {@code senderSigningKey} will not be closed. * * @param senderSigningKey the serialized Tink signing key. * @throws GeneralSecurityException if the initialization fails. * @throws IOException if the given sender signing key cannot be read. */ public RsaEcdsaEncrypterManager(InputStream senderSigningKey) throws GeneralSecurityException, IOException { KeysetHandle signingKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withInputStream(senderSigningKey)); senderSigner = PublicKeySignFactory.getPrimitive(signingKeyHandle); }
/** * 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)); } }
/** * Constructs a new RSA-ECDSA EncrypterManager. * * <p>Please note that the {@link InputStream} {@code senderSigningKey} will not be closed. * * @param senderSigningKey the serialized Tink signing key. * @throws GeneralSecurityException if the initialization fails. * @throws IOException if the given sender signing key cannot be read. */ public RsaEcdsaEncrypterManager(InputStream senderSigningKey) throws GeneralSecurityException, IOException { KeysetHandle signingKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withInputStream(senderSigningKey)); senderSigner = PublicKeySignFactory.getPrimitive(signingKeyHandle); }
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)); } }
try { symmetricKeyHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(symmetricKeyBytes)); } catch (IOException e) { throw new GeneralSecurityException("hybrid rsa decryption failed: ", e);
ByteArrayOutputStream symmetricKeyOutputStream = new ByteArrayOutputStream(); try { CleartextKeysetHandle.write( symmetricKeyHandle, BinaryKeysetWriter.withOutputStream(symmetricKeyOutputStream)); } catch (IOException e) {
try { symmetricKeyHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(symmetricKeyBytes)); } catch (IOException e) { throw new GeneralSecurityException("hybrid rsa decryption failed: ", e);
ByteArrayOutputStream symmetricKeyOutputStream = new ByteArrayOutputStream(); try { CleartextKeysetHandle.write( symmetricKeyHandle, BinaryKeysetWriter.withOutputStream(symmetricKeyOutputStream)); } catch (IOException e) {
static PublicKeyVerify createTestSenderVerifier() throws GeneralSecurityException, IOException { KeysetHandle verificationKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withBytes(TestUtils.getBytes("verification_key.dat"))); return PublicKeyVerifyFactory.getPrimitive(verificationKeyHandle); }
static PublicKeySign createTestSenderSigner() throws GeneralSecurityException, IOException { KeysetHandle signingKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withBytes(TestUtils.getBytes("signing_key.dat"))); return PublicKeySignFactory.getPrimitive(signingKeyHandle); }