Class: Peatio::Security::KeyGenerator
- Inherits:
-
Object
- Object
- Peatio::Security::KeyGenerator
- Defined in:
- lib/peatio/security/key_generator.rb
Instance Attribute Summary collapse
-
#private ⇒ Object
readonly
Returns the value of attribute private.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
Instance Method Summary collapse
-
#initialize ⇒ KeyGenerator
constructor
A new instance of KeyGenerator.
- #save(folder) ⇒ Object
- #write(filename, text) ⇒ Object
Constructor Details
#initialize ⇒ KeyGenerator
Returns a new instance of KeyGenerator.
8 9 10 11 12 13 |
# File 'lib/peatio/security/key_generator.rb', line 8 def initialize OpenSSL::PKey::RSA.generate(2048).tap do |pkey| @public = pkey.public_key.to_pem @private = pkey.to_pem end end |
Instance Attribute Details
#private ⇒ Object (readonly)
Returns the value of attribute private.
6 7 8 |
# File 'lib/peatio/security/key_generator.rb', line 6 def private @private end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
6 7 8 |
# File 'lib/peatio/security/key_generator.rb', line 6 def public @public end |
Instance Method Details
#save(folder) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/peatio/security/key_generator.rb', line 15 def save(folder) FileUtils.mkdir_p(folder) unless File.exists?(folder) write(File.join(folder, 'rsa-key'), @private) write(File.join(folder, 'rsa-key.pub'), @public) end |
#write(filename, text) ⇒ Object
22 23 24 |
# File 'lib/peatio/security/key_generator.rb', line 22 def write(filename, text) File.open(filename, 'w') { |file| file.write(text) } end |