Search in sources :

Example 11 with KeysetManager

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

the class TinkeyUtil method createKey.

/**
 * Creates and adds a new key to an existing keyset. The new key becomes the primary key if {@code
 * type} is {@link CommandType#ROTATE}.
 */
public static void createKey(CommandType type, OutputStream outputStream, String outFormat, InputStream inputStream, String inFormat, String masterKeyUri, String credentialPath, KeyTemplate keyTemplate) throws GeneralSecurityException, IOException {
    KeysetManager manager = KeysetManager.withKeysetHandle(getKeysetHandle(inputStream, inFormat, masterKeyUri, credentialPath));
    switch(type) {
        case ADD_KEY:
            manager.add(keyTemplate);
            break;
        case ROTATE_KEYSET:
            manager.rotate(toProto(keyTemplate));
            break;
        default:
            throw new GeneralSecurityException("invalid command");
    }
    writeKeyset(manager.getKeysetHandle(), outputStream, outFormat, masterKeyUri, credentialPath);
}
Also used : KeysetManager(com.google.crypto.tink.KeysetManager) GeneralSecurityException(java.security.GeneralSecurityException)

Aggregations

KeysetManager (com.google.crypto.tink.KeysetManager)11 KeyTemplate (com.google.crypto.tink.KeyTemplate)7 KeysetHandle (com.google.crypto.tink.KeysetHandle)7 Test (org.junit.Test)7 GeneralSecurityException (java.security.GeneralSecurityException)3 IOException (java.io.IOException)2 KeyData (com.google.crypto.tink.proto.KeyData)1 KeysetInfo (com.google.crypto.tink.proto.KeysetInfo)1 ProtoKey (com.google.crypto.tink.tinkkey.internal.ProtoKey)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 JsonReader (com.google.gson.stream.JsonReader)1 ByteString (com.google.protobuf.ByteString)1 StringReader (java.io.StringReader)1