Skip to content

Commit

Permalink
Add key pair generator
Browse files Browse the repository at this point in the history
  • Loading branch information
metin committed Aug 8, 2014
1 parent 63af623 commit 518c60b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rsa_authority.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
require 'openssl'
require 'base64'
require 'cgi'

require "rsa_authority/version"
require "rsa_authority/key_gen"


module RSAAuthority
# Your code goes here...
Expand Down
11 changes: 11 additions & 0 deletions lib/rsa_authority/key_gen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module RSAAuthority
class KeyGen
def self.generate(key_name)
rsa_private_key = OpenSSL::PKey::RSA.generate(2048)

File.open("#{key_name}.pem", "w") { |io| io.write(rsa_private_key.to_s) }

File.open("#{key_name}.pub", "w") { |io| io.write(rsa_private_key.public_key) }
end
end
end
16 changes: 16 additions & 0 deletions spec/key_gen_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe RSAAuthority::KeyGen do
let(:test_key_name) { 'example_key' }
let(:public_key) { "#{test_key_name}.pub" }
let(:private_key) { "#{test_key_name}.pem" }

after { File.delete public_key, private_key }

it "generates public and privete key pair" do
RSAAuthority::KeyGen.generate(test_key_name)

expect(File.exists?(public_key)).to be(true)
expect(File.exists?(private_key)).to be(true)
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rsa_authority'

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
Expand Down

0 comments on commit 518c60b

Please sign in to comment.