43 lines
4.4 KiB
Ruby
43 lines
4.4 KiB
Ruby
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_key22="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEApOebWmRV/ooNq5Ks04YnDU7pEezGShGvaiF0cIvn9jvmYHu0\nFialojvJV3VpB6xE6QBPXZ0Pi1lokZ9dMx8F5UWNx9WA7wf7xK3hAJLNml+GeewF\nou8vk/Ry7n6diLxETNVd7YzPvztn5qaMp/DXa+65i11H8a/XXqR7kCVnCevVlufh\nNr/Dp6dW31W8TInnDQasJFMZ8GY7f+tCwLXNc0M8p+TeDp9xmXHOrEB+S/mgbUOF\nXgRr6icbMmlT9bsAxYHrrDkcVxJhs0hq5vD3BaoK06gcZEnN7/HVNzgVSOYNsVNh\n9006cMgDSOwc9F8aulP7cr8k74INq1xswoGs9wIDAQABAoIBAHayc2NkF3YJXv+h\nqx7yUEfHBgKuAKiuBCqLfCnKuqPFx/So9h5/oPeeuzVlwL0SJePlIjuK4vZ128v9\n/vLeILtADmbJ6m2jvHh8hBmKkc3Ndplp50C5k/CWoufCYZhbk3oOlvZ3Rc4rb4VZ\nWqNDu3voMMv8z91KqeZo1LwUAA/l9mU++zLkRA6qOuWGBJFsM8YpshzxL5lzRUb3\n7y+YJDyUZztfzKwr6pqm1n9B2e6e+znCw1vMZXp2TbUrpvrrXSxlgdNuK68SkZX6\nTdZUD8y0viwaioRVf3vR+e/Bf7yZannGdvcmVGs0A7dq9QgHkakqNHiRkQgwviSq\nbjBo7dECgYEAzekeP5j/dAPkv9X4qnmZ4du/+ZgrQrJckDD/JuNIBmQT9m286l4P\nmb2TBcWkswVOZaS5Qy2bN/69rwIbcdvbaROGBCabn3ATK4fSzmUk31M2rRKYZqaU\nMi0W2g2YtSRg+bV6S7aFXa98j5+JlqJeDZQoRuvL68ooq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59E6F5iv48mF3w0M28MGn4N47VRSmGzwWZ\nJeTQhDDBFCxeZ45Xn2Xln9Cw15xUDwmzi7zhSMUtdkUK0x3q0a1xfLtgWE775lhl\njjzpAoGAdUXFW1elfjXpfIYZf7vUV7MPquKL7qAcopd96XBszhOn7g+ibzem+wgt\n1UTSeOBESYANHeJk2MuWPSRXk/FlQETVIcPAEp0kxbwQE+7YEdrMVeDcIe5lPwGD\n+WuS3kg0MPgUrXZXn74gcwWmSIOyHfqXULqOxWE25uU2icdV+2w=\n-----END RSA PRIVATE KEY-----\n"
|
|
private_key = OpenSSL::PKey::RSA.new(private_key33)
|
|
# puts private_key.to_json
|
|
|
|
# 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: "782"
|
|
}
|
|
|
|
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
|
|
|
|
# decoded_token = JWT.decode jwt, nil, false
|
|
begin
|
|
decoded_token = JWT.decode jwt, rsa_private, true, { algorithm: 'RS256' }
|
|
rescue JWT::DecodeError
|
|
puts "jwt is not mmmmmm"
|
|
end
|
|
|
|
#
|
|
puts decoded_token[0]
|
|
puts decoded_token[0]["iss"]
|
|
|
|
# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s
|
|
|
|
|