@CanIgnoreReturnValue
  public synchronized int addNewKey(
      com.google.crypto.tink.proto.KeyTemplate keyTemplate, boolean asPrimary)
      throws GeneralSecurityException {
    Keyset.Key key = newKey(keyTemplate);
    keysetBuilder.addKey(key);
    if (asPrimary) {
      keysetBuilder.setPrimaryKeyId(key.getKeyId());
    }
    return key.getKeyId();
  }
Generates a fresh key using {@code keyTemplate} and returns the {@code keyId} of it. In case
{@code asPrimary} is true the generated key will be the new primary.
java_src/src/main/java/com/google/crypto/tink/KeysetManager.java