private static KeyData getPublicKeyDataFromRegistry(KeyData privateKeyData)
      throws GeneralSecurityException {
    if (privateKeyData.getKeyMaterialType() != KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE) {
      throw new GeneralSecurityException("The keyset contains a non-private key");
    }
    KeyData publicKeyData =
        Registry.getPublicKeyData(privateKeyData.getTypeUrl(), privateKeyData.getValue());
    return publicKeyData;
  }
If the managed keyset contains private keys, returns a {@link KeysetHandle} of the public keys.

@throws GeneralSecurityException if the managed keyset is null or if it contains any
    non-private keys.
java_src/src/main/java/com/google/crypto/tink/KeysetHandle.java