Class: Peatio::Security::KeyGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/peatio/security/key_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKeyGenerator

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

#privateObject (readonly)

Returns the value of attribute private.



6
7
8
# File 'lib/peatio/security/key_generator.rb', line 6

def private
  @private
end

#publicObject (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