krypton 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a86fd0d5ca7918e968df272fc4022b790c7b054691414801b03d68edbaa617d
4
- data.tar.gz: fd6f830536481adb2705379402e30b1f792bc19b56a29615838086a62666a2a3
3
+ metadata.gz: 1dfb0af7604609af2a13bdde8bb3012fa3ae6406c0a8eb4878d426d2afef4fee
4
+ data.tar.gz: 4c6c62b8dc7843b59bcaacca7adf356e38cc9ea438af7fb83bc670cfce8a73b5
5
5
  SHA512:
6
- metadata.gz: 1f97e912553c4cef694404cddf467b22b0f7cb4b7cb795cc512dae98e148fbf09663473ea2f1426abced2710e3d15d46356c623c127b26ac9e51dd3b205f0a36
7
- data.tar.gz: 440ce6cb87f58438d739143d38ea9a76c46b18e2ad138e37a8a3866db901a268152ef368c09b3de80b360144dc5685d501197a55035319763b7d0e0c76923409
6
+ metadata.gz: 3989a7406a2b2969d980470e205d70807efb093433400538490cbc1390632d36ddb31ff079c63a490aea2605d97fa6266cf3f759494410a2d8cbb0260bc51d95
7
+ data.tar.gz: c94dc4c64031b3f802476c2f14e0d1bd1fa323fe5069ecd1d29755f55110a64e2d5fc11e7c9a39e52da4869c122eaeb3c8f2294a470a4d38020811327a7d071f
@@ -1,25 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- krypton (0.1.6)
4
+ krypton (0.1.8)
5
5
  aes
6
6
  colorize
7
7
  commander
8
+ http
8
9
  paint
9
10
  rotp
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
15
+ addressable (2.6.0)
16
+ public_suffix (>= 2.0.2, < 4.0)
14
17
  aes (0.5.0)
15
18
  colorize (0.8.1)
16
- commander (4.4.6)
17
- highline (~> 1.7.2)
19
+ commander (4.4.7)
20
+ highline (~> 2.0.0)
18
21
  diff-lcs (1.3)
19
- highline (1.7.10)
20
- paint (2.0.1)
22
+ domain_name (0.5.20190701)
23
+ unf (>= 0.0.5, < 1.0.0)
24
+ highline (2.0.2)
25
+ http (4.1.1)
26
+ addressable (~> 2.3)
27
+ http-cookie (~> 1.0)
28
+ http-form_data (~> 2.0)
29
+ http_parser.rb (~> 0.6.0)
30
+ http-cookie (1.0.3)
31
+ domain_name (~> 0.5)
32
+ http-form_data (2.1.1)
33
+ http_parser.rb (0.6.0)
34
+ paint (2.1.0)
35
+ public_suffix (3.1.1)
21
36
  rake (10.5.0)
22
- rotp (3.3.1)
37
+ rotp (5.1.0)
38
+ addressable (~> 2.5)
23
39
  rspec (3.8.0)
24
40
  rspec-core (~> 3.8.0)
25
41
  rspec-expectations (~> 3.8.0)
@@ -33,6 +49,9 @@ GEM
33
49
  diff-lcs (>= 1.2.0, < 2.0)
34
50
  rspec-support (~> 3.8.0)
35
51
  rspec-support (3.8.0)
52
+ unf (0.1.4)
53
+ unf_ext
54
+ unf_ext (0.0.7.6)
36
55
 
37
56
  PLATFORMS
38
57
  ruby
@@ -44,4 +63,4 @@ DEPENDENCIES
44
63
  rspec (~> 3.0)
45
64
 
46
65
  BUNDLED WITH
47
- 1.16.4
66
+ 1.17.3
@@ -13,10 +13,10 @@ options = {}
13
13
  options[:outfile] = ''
14
14
  options[:raw] = false
15
15
  OptionParser.new do |opts|
16
- opts.banner = "A command-line tool to encrypt and decrypt data in multiple formats.\n\nUsage: #{File.basename($PROGRAM_NAME)} [options] [task] \"message\" \"key\"\nKrypton version: #{Paint[VERSION, '#2ecc71']}"
16
+ opts.banner = "A command-line tool to encrypt and decrypt data in multiple formats.\n\nUsage: #{File.basename($PROGRAM_NAME)} [options] [task] \"data\" [\"key\"]\nKrypton version: #{Paint[VERSION, '#2ecc71']}"
17
17
  opts.separator Paint["\nGlobal Options: ", '#95a5a6']
18
18
 
19
- opts.on('-s', '--std', 'Print output suitable for piping.') do
19
+ opts.on('-s', '--std', 'Print output suitable for piping.') do
20
20
  options[:std] = true
21
21
  end
22
22
 
@@ -72,22 +72,21 @@ while (opt = ARGV.shift) do
72
72
  puts "#{ARGV[ARGV.length - 2] + ' => '}#{Paint[result.strip, '#2ecc71']}"
73
73
  end
74
74
  exit 0
75
-
76
-
75
+
77
76
  # HASHING
78
77
  when 'hash'
79
78
 
80
79
  data = ARGV[ARGV.length - 1] || gets
81
80
 
82
81
  result = Krypton::SHA.hash(data, options[:raw])
83
-
82
+
84
83
  if options[:std]
85
84
  puts result.strip
86
85
  else
87
86
  puts "#{data + ' => '}#{Paint[result.strip, '#2ecc71']}"
88
87
  end
89
88
  exit 0
90
-
89
+
91
90
  when 'uuid'
92
91
  if options[:std]
93
92
  puts SecureRandom.uuid
@@ -108,7 +107,7 @@ while (opt = ARGV.shift) do
108
107
  end
109
108
  exit 0
110
109
  end
111
-
110
+
112
111
  when 'b64e'
113
112
  data = ARGV[ARGV.length - 1] || gets
114
113
  if options[:std]
@@ -134,6 +133,22 @@ while (opt = ARGV.shift) do
134
133
  puts "#{filename} => #{Paint[Krypton::SHA.checksum(filename, options[:raw]), '#2ecc71']}"
135
134
  end
136
135
  exit 0
136
+ when 'lookup'
137
+ hashes_key = ENV['HASHES_API_KEY']
138
+ hash = ARGV[ARGV.length - 1]
139
+ if hashes_key.nil?
140
+ puts "A valid hashes.org API key is required to use this feature."
141
+ puts "Please set the environment variable HASHES_API_KEY to your key."
142
+ exit 1
143
+ end
144
+
145
+ begin
146
+ Krypton::Lookup.lookup(hash, hashes_key)
147
+ rescue StandardError => e
148
+ puts "ERROR: #{e.message}"
149
+ exit 1
150
+ end
151
+
137
152
  else
138
153
  puts "#{opt} is not a valid action!"
139
154
  exit 1
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "aes"
22
22
  spec.add_runtime_dependency "commander"
23
23
  spec.add_runtime_dependency "rotp"
24
+ spec.add_runtime_dependency "http"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.16"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
@@ -4,6 +4,8 @@ require 'optparse'
4
4
  require 'paint'
5
5
  require 'securerandom'
6
6
  require 'rotp'
7
+ require 'http'
8
+ require 'json'
7
9
 
8
10
  # lib files
9
11
  require_relative './core/constants.rb'
@@ -11,6 +13,7 @@ require_relative './core/base64.rb'
11
13
  require_relative './core/text.rb'
12
14
  require_relative './core/aes.rb'
13
15
  require_relative './core/sha.rb'
16
+ require_relative './core/lookup.rb'
14
17
 
15
18
  module Krypton
16
19
  end
@@ -1,4 +1,4 @@
1
- VERSION = "0.1.8"
1
+ VERSION = "0.2.0"
2
2
  AUTHORS = {
3
3
  'Carter Brainerd' => '0xCB[at]protonmail[dot]com'
4
4
  }
@@ -0,0 +1,61 @@
1
+ # This software uses the Hashes.org API. It is used to respect the work of all who help Hashes.org keep running.
2
+ module Krypton
3
+ class Lookup
4
+
5
+ def self.lookup(hash, key)
6
+ base_url = "https://hashes.org/api.php?key=#{key}&query=#{hash}"
7
+
8
+ # Fire off the request and objectify it
9
+ results = JSON.parse(HTTP.get(base_url).to_s)
10
+
11
+ # First check if it was successful
12
+
13
+ if results["status"] == "error"
14
+ puts "Error in hash lookup: #{results["errorMessage"]}"
15
+ exit 1
16
+ end
17
+
18
+ unless results["status"] == "success"
19
+ puts "Error in hash lookup: request failed"
20
+ exit 1
21
+ end
22
+
23
+ # It was successful, now check if it yielded any valid results
24
+ # An example result looks like this
25
+ # {
26
+ # "status":"success",
27
+ # "result":{
28
+ # "739c5b1cd5681e668f689aa66bcc254c":{
29
+ # "plain":"test",
30
+ # "hexplain":"74657374",
31
+ # "algorithm":"MD5X5PLAIN"
32
+ # },
33
+ # "319a96b23c3e875a9a1491a6ba4d46de7495ea35":null
34
+ # }
35
+ # }
36
+
37
+ # Just get the results section (it's an array)
38
+ hashes = results["result"]
39
+
40
+ hashes.each do |r|
41
+ # r looks like this for a valid hash:
42
+ # {"hash" => {"plain"=>"password", "hexplain"=>"70617373776f7264", "algorithm"=>"SHA1"}}
43
+ # and like this for an invalid hash
44
+ # {"hash" => nil}
45
+
46
+ # If a hash wasn't found
47
+ if r[1].nil?
48
+ puts "Could not find result for hash #{r[0]}."
49
+ else
50
+ puts
51
+ puts "Result found:"
52
+ puts " Hash: #{Paint[r[0], '#2ecc71']}"
53
+ puts " Plaintext: #{Paint[r[1]["plain"], '#2ecc71']}"
54
+ puts " Algorithm: #{Paint[r[1]["algorithm"], '#2ecc71']}"
55
+ end
56
+
57
+ exit 0
58
+ end
59
+ end
60
+ end
61
+ end
@@ -4,17 +4,18 @@ def vprint(*args)
4
4
  end
5
5
 
6
6
  TASKS_HELP =
7
- %Q{ encrypt Encrypt the message with the given key (AES).
8
- decrypt Decrypt the message with the given key (AES).
9
- hash Hash a given message with SHA-256.
10
- sum Retrieve the SHA-256 checksum of a given file.
11
- uuid Generate a random UUID.
12
- totp Generate a Time-based One Time Password.
13
- b64e Encode data in base64.
14
- b64d Decode base64 data.
7
+ %Q{ encrypt Encrypt the message with the given key (AES).
8
+ decrypt Decrypt the message with the given key (AES).
9
+ hash Hash a given message with SHA-256.
10
+ sum Retrieve the SHA-256 checksum of a given file.
11
+ uuid Generate a random UUID.
12
+ totp Generate a Time-based One Time Password.
13
+ b64e Encode data in base64.
14
+ b64d Decode base64 data.
15
+ lookup Check if a hash has been cracked (hashes.org API key needed).
15
16
 
16
17
  #{Paint['Examples', '#95a5a6']}
17
- #{Paint['$ krypton encrypt "mymessage" "mykey"', '#2ecc71']} #{Paint['=> ckhJWXcyTE1leENLOWpBQzJWbElMdz09Cg==', '#95a5a6']}
18
+ #{Paint['$ krypton encrypt "mymessage" "mykey"', '#2ecc71']} => #{Paint['ckhJWXcyTE1leENLOWpBQzJWbElMdz09Cg==', '#95a5a6']}
18
19
  #{Paint['$ krypton hash "mymessage"', '#2ecc71']} => #{Paint['S3ONp9WM7/rCMeuUnvWDzp5dxbuSVsOV6bI5AJvRqCc=', '#95a5a6']}
19
20
  #{Paint['$ krypton totp "mygreatsecret"', '#2ecc71']} => #{Paint['778501', '#95a5a6']}
20
21
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krypton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cbrnrd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-30 00:00:00.000000000 Z
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: http
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +162,7 @@ files:
148
162
  - lib/core/aes.rb
149
163
  - lib/core/base64.rb
150
164
  - lib/core/constants.rb
165
+ - lib/core/lookup.rb
151
166
  - lib/core/sha.rb
152
167
  - lib/core/text.rb
153
168
  - scripts/build_install_local.sh