private static com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey getProtoPublicKey(
      JwtRsaSsaPkcs1PublicKey key) throws GeneralSecurityException {
    com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey.Builder builder =
        com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey.newBuilder()
            .setVersion(0)
            .setAlgorithm(ALGORITHM_CONVERTER.toProtoEnum(key.getParameters().getAlgorithm()))
            .setN(encodeBigInteger(key.getModulus()))
            .setE(encodeBigInteger(key.getParameters().getPublicExponent()));
    if (key.getParameters().getKidStrategy().equals(JwtRsaSsaPkcs1Parameters.KidStrategy.CUSTOM)) {
      builder.setCustomKid(
          com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey.CustomKid.newBuilder()
              .setValue(key.getKid().get())
              .build());
    }
    return builder.build();
  }
Encodes a BigInteger using a big-endian encoding.
java_src/src/main/java/com/google/crypto/tink/jwt/JwtRsaSsaPkcs1ProtoSerialization.java