Top Level Namespace

Defined Under Namespace

Modules: Eco, Ecoportal Classes: Exception, Hash

Constant Summary collapse

ASSETS =
Eco::Assets.new
SCR =
Eco::CLI::Scripting.new
Handy =
Eco::Assets::Language.new

Instance Method Summary collapse

Instance Method Details

#run!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/eco/data/crypto/encryption.rb', line 10

def run! # this will run only if called from command line (not when require'd nor load'd)
  include Eco::CLI::Scripting
  include Eco::Data::Crypto
  # script arguments
  keygen = get_arg("-keygen")
  filename = get_arg("-keygen", with_param: true)
  ssh = get_arg("-ssh")
  length = get_arg("-length", with_param: true)
  check_rsa_pairs = get_arg("-keypairs")
  key_filename = get_arg("-keypairs", with_param: true)

  # methods
  case true
  when keygen
    puts "++ keygen RSA ++"
    #pp ::OpenSSL.constants.sort
    cr = Eco::Data::Crypto::OpenSSL.new
    case true
    when ssh
      puts "think about installing this library: https://rubygems.org/gems/sshkey"
      puts "GitHub: https://github.com/bensie/sshkey"
      puts "or add this Ruby solution to convert to ssh-rsa: https://stackoverflow.com/a/3162593/4352306"
      exit(1)
      cr.rsa_keygen_ssh(filename: filename)
    else
      cr.rsa_keygen(filename: filename)
    end
  when check_rsa_pairs
    puts "++ checking file pairs ++"
    begin
      key_filename = "rsa" if !key_filename
      priv = File.read(key_filename + '.pem')
      pub = File.read(key_filename + '.pub')
    rescue
      puts "could not find files with basename: #{key_filename}"
      exit(1)
    end
    cr = Eco::Data::Crypto::OpenSSL.new
    equals = cr.rsa_keypairs?(priv, pub)
    if equals
      puts "the pair #{key_filename} seem to be for one to another!"
    else
      puts "those files with base name #{key_filename} are not a rsa pair"
    end
  end
end