require 'openssl'
require 'jwt'  # https://rubygems.org/gems/jwt

# Private key contents
private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem")
private_key = OpenSSL::PKey::RSA.new(private_pem)

# Generate the JWT
payload = {
  # issued at time, 60 seconds in the past to allow for clock drift
  iat: Time.now.to_i - 60,
  # JWT expiration time (10 minute maximum)
  exp: Time.now.to_i + (10 * 60),
  # GitHub App's identifier
  iss: "209248"
}

jwt = JWT.encode(payload, private_key, "RS256")
puts jwt
# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s
#
# rsa_private = OpenSSL::PKey::RSA.new(private_key33)
# rsa_public = rsa_private.public_key
#
#

# puts decoded_token[0]
# puts decoded_token[0]["iss"]

# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s


