keycert.rb 551 Bytes
require 'openssl'

key = OpenSSL::PKey::RSA.new 4096

open 'private_key.pem', 'w' do |io| io.write key.to_pem end
open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end

name = OpenSSL::X509::Name.parse 'CN=lex-deeit/DC=weird-web-workers/DC=org'

cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
cert.not_after = Time.now + 3600

cert.public_key = key.public_key
cert.subject = name
cert.sign key, OpenSSL::Digest::SHA256.new

open 'public-key.crt', 'w' do |io| io.write cert.to_pem end