Last Updated: September 21, 2022
·
5.606K
· Lex S

Generate a self-signed X509 certificate with ruby

Create a public X509 certificate called 'certificate.pem' and a private rsa key called 'private_key.pem':
require "openssl"

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

name = OpenSSL::X509::Name.parse '/CN=nobody'

cert = OpenSSL::X509::Certificate.new

cert.version = 2

cert.serial = 0

cert.not_before = Time.now

cert.not_after = Time.now + 606024364.251

cert.publickey = key.publickey

cert.subject = name

cert.issuer = name

cert.sign key, OpenSSL::Digest.new('SHA256')

open 'certificate.pem', 'w' do |io| io.write cert.to_pem end

open 'privatekey.pem', 'w' do |io| io.write key.topem end

The ruby openssl docs have other great examples.

Mailer To Go is an email provider on Heroku that is by developers for developers.
We've spend too much time dealing with other mailing services, and decided to create our own.