Commit 9cde449f60ef4801792423e88d731a5ef574e254
1 parent
063d9bfe
Example generate self signed key/cert
Showing
1 changed file
with
20 additions
and
0 deletions
doc/keycert.rb
0 → 100644
1 | +require 'openssl' | ||
2 | + | ||
3 | +key = OpenSSL::PKey::RSA.new 4096 | ||
4 | + | ||
5 | +open 'private_key.pem', 'w' do |io| io.write key.to_pem end | ||
6 | +open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end | ||
7 | + | ||
8 | +name = OpenSSL::X509::Name.parse 'CN=lex-deeit/DC=weird-web-workers/DC=org' | ||
9 | + | ||
10 | +cert = OpenSSL::X509::Certificate.new | ||
11 | +cert.version = 2 | ||
12 | +cert.serial = 0 | ||
13 | +cert.not_before = Time.now | ||
14 | +cert.not_after = Time.now + 3600 | ||
15 | + | ||
16 | +cert.public_key = key.public_key | ||
17 | +cert.subject = name | ||
18 | +cert.sign key, OpenSSL::Digest::SHA256.new | ||
19 | + | ||
20 | +open 'public-key.crt', 'w' do |io| io.write cert.to_pem end |
Please
register
or
login
to post a comment