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);
}
Aggregations