Search in sources :

Example 1 with KeysetWriter

use of com.google.crypto.tink.KeysetWriter in project tink by google.

the class CreatePublicKeysetCommand method create.

/**
 * Extracts public keys from {@code inputStream} (using {@code credentialPath} and
 * {@code masterKeyUri} to decrypt if it is encrypted) and writes public keys to
 * {@code outputStream}.
 */
public static void create(OutputStream outputStream, String outFormat, InputStream inputStream, String inFormat, String masterKeyUri, String credentialPath) throws Exception {
    KeysetHandle handle = TinkeyUtil.getKeysetHandle(inputStream, inFormat, masterKeyUri, credentialPath);
    KeysetWriter writer = TinkeyUtil.createKeysetWriter(outputStream, outFormat);
    CleartextKeysetHandle.write(handle.getPublicKeysetHandle(), writer);
}
Also used : CleartextKeysetHandle(com.google.crypto.tink.CleartextKeysetHandle) KeysetHandle(com.google.crypto.tink.KeysetHandle) KeysetWriter(com.google.crypto.tink.KeysetWriter)

Example 2 with KeysetWriter

use of com.google.crypto.tink.KeysetWriter in project tink by google.

the class TinkeyUtil method writeKeyset.

/**
 * Writes the keyset managed by {@code handle} to {@code outputStream} with format {@code
 * outFormat}. Maybe encrypt it with {@code masterKeyUri} and {@code credentialPath}.
 */
public static void writeKeyset(KeysetHandle handle, OutputStream outputStream, String outFormat, String masterKeyUri, String credentialPath) throws GeneralSecurityException, IOException {
    KeysetWriter writer = createKeysetWriter(outputStream, outFormat);
    if (masterKeyUri != null) {
        Aead masterKey = KmsClients.getAutoLoaded(masterKeyUri).withCredentials(credentialPath).getAead(masterKeyUri);
        handle.write(writer, masterKey);
    } else {
        CleartextKeysetHandle.write(handle, writer);
    }
}
Also used : JsonKeysetWriter(com.google.crypto.tink.JsonKeysetWriter) KeysetWriter(com.google.crypto.tink.KeysetWriter) BinaryKeysetWriter(com.google.crypto.tink.BinaryKeysetWriter) Aead(com.google.crypto.tink.Aead)

Aggregations

KeysetWriter (com.google.crypto.tink.KeysetWriter)2 Aead (com.google.crypto.tink.Aead)1 BinaryKeysetWriter (com.google.crypto.tink.BinaryKeysetWriter)1 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)1 JsonKeysetWriter (com.google.crypto.tink.JsonKeysetWriter)1 KeysetHandle (com.google.crypto.tink.KeysetHandle)1