symmetric-encryption 4.3.1 → 4.3.2
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 +4 -4
- data/Rakefile +9 -9
- data/bin/symmetric-encryption +1 -1
- data/lib/symmetric-encryption.rb +1 -1
- data/lib/symmetric_encryption.rb +9 -9
- data/lib/symmetric_encryption/active_record/attr_encrypted.rb +1 -1
- data/lib/symmetric_encryption/cipher.rb +14 -10
- data/lib/symmetric_encryption/cli.rb +51 -51
- data/lib/symmetric_encryption/coerce.rb +3 -3
- data/lib/symmetric_encryption/config.rb +27 -26
- data/lib/symmetric_encryption/core.rb +22 -22
- data/lib/symmetric_encryption/encoder.rb +8 -8
- data/lib/symmetric_encryption/generator.rb +7 -3
- data/lib/symmetric_encryption/header.rb +12 -12
- data/lib/symmetric_encryption/key.rb +1 -1
- data/lib/symmetric_encryption/keystore.rb +20 -20
- data/lib/symmetric_encryption/keystore/aws.rb +6 -6
- data/lib/symmetric_encryption/keystore/environment.rb +4 -4
- data/lib/symmetric_encryption/keystore/file.rb +17 -3
- data/lib/symmetric_encryption/keystore/gcp.rb +6 -6
- data/lib/symmetric_encryption/keystore/heroku.rb +1 -1
- data/lib/symmetric_encryption/keystore/memory.rb +1 -1
- data/lib/symmetric_encryption/railtie.rb +6 -6
- data/lib/symmetric_encryption/railties/mongoid_encrypted.rb +3 -3
- data/lib/symmetric_encryption/railties/symmetric_encryption_validator.rb +1 -1
- data/lib/symmetric_encryption/reader.rb +13 -13
- data/lib/symmetric_encryption/rsa_key.rb +1 -1
- data/lib/symmetric_encryption/symmetric_encryption.rb +23 -17
- data/lib/symmetric_encryption/utils/aws.rb +8 -8
- data/lib/symmetric_encryption/utils/files.rb +3 -3
- data/lib/symmetric_encryption/utils/re_encrypt_files.rb +5 -5
- data/lib/symmetric_encryption/version.rb +1 -1
- data/lib/symmetric_encryption/writer.rb +17 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4054c7a61802055fd46d4effd1f3222369a1b46f23aeeadaae0322d392b7dcc1
|
4
|
+
data.tar.gz: b367ad236ab6f52d97bf28425f1c7bb1fc824b1c573c6528adb276f842dd97ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0318de85ab6308c6dc7748d0096b18693d3b1cd8266ac7920a8033f9c220981b222a1d2e594bcd6f2d08700c40dbbc6e32159ab2b235b6f2b58ff5bb2dc4a2
|
7
|
+
data.tar.gz: 5a29bd465b788a8e28e3f84435fb5d03355fcd9d31fded9d4700eea47cec1a02dd2675c84b36d72fe2e16a9ee4dbafa2b8b401519cebf58c17abaaf9741f9aae
|
data/Rakefile
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# Setup bundler to avoid having to run bundle exec all the time.
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "rubygems"
|
3
|
+
require "bundler/setup"
|
4
4
|
|
5
|
-
require
|
6
|
-
require_relative
|
5
|
+
require "rake/testtask"
|
6
|
+
require_relative "lib/symmetric_encryption/version"
|
7
7
|
|
8
8
|
task :gem do
|
9
|
-
system
|
9
|
+
system "gem build symmetric-encryption.gemspec"
|
10
10
|
end
|
11
11
|
|
12
12
|
task publish: :gem do
|
13
13
|
system "git tag -a v#{SymmetricEncryption::VERSION} -m 'Tagging #{SymmetricEncryption::VERSION}'"
|
14
|
-
system
|
14
|
+
system "git push --tags"
|
15
15
|
system "gem push symmetric-encryption-#{SymmetricEncryption::VERSION}.gem"
|
16
16
|
system "rm symmetric-encryption-#{SymmetricEncryption::VERSION}.gem"
|
17
17
|
end
|
18
18
|
|
19
19
|
Rake::TestTask.new(:test) do |t|
|
20
|
-
t.pattern =
|
20
|
+
t.pattern = "test/**/*_test.rb"
|
21
21
|
t.verbose = true
|
22
22
|
t.warning = false
|
23
23
|
end
|
24
24
|
|
25
25
|
# By default run tests against all appraisals
|
26
|
-
if !ENV[
|
27
|
-
require
|
26
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
27
|
+
require "appraisal"
|
28
28
|
task default: :appraisal
|
29
29
|
else
|
30
30
|
task default: :test
|
data/bin/symmetric-encryption
CHANGED
data/lib/symmetric-encryption.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require "symmetric_encryption"
|
data/lib/symmetric_encryption.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require "symmetric_encryption/core"
|
2
2
|
|
3
3
|
# Add extensions. Gems are no longer order dependent.
|
4
4
|
begin
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "rails"
|
6
|
+
require "symmetric_encryption/railtie"
|
7
7
|
rescue LoadError
|
8
8
|
end
|
9
9
|
|
10
10
|
begin
|
11
|
-
require
|
11
|
+
require "active_support"
|
12
12
|
ActiveSupport.on_load(:active_record) do
|
13
|
-
require
|
14
|
-
require
|
13
|
+
require "symmetric_encryption/active_record/attr_encrypted"
|
14
|
+
require "symmetric_encryption/railties/symmetric_encryption_validator"
|
15
15
|
|
16
|
-
if ActiveRecord.version >= Gem::Version.new(
|
16
|
+
if ActiveRecord.version >= Gem::Version.new("5.0.0")
|
17
17
|
ActiveRecord::Type.register(:encrypted, SymmetricEncryption::ActiveRecord::EncryptedAttribute)
|
18
18
|
end
|
19
19
|
|
@@ -21,8 +21,8 @@ begin
|
|
21
21
|
end
|
22
22
|
|
23
23
|
ActiveSupport.on_load(:mongoid) do
|
24
|
-
require
|
25
|
-
require
|
24
|
+
require "symmetric_encryption/railties/mongoid_encrypted"
|
25
|
+
require "symmetric_encryption/railties/symmetric_encryption_validator"
|
26
26
|
end
|
27
27
|
rescue LoadError
|
28
28
|
end
|
@@ -51,7 +51,7 @@ module SymmetricEncryption
|
|
51
51
|
random_iv = true if random_iv.nil? && SymmetricEncryption.randomize_iv?
|
52
52
|
|
53
53
|
if random_iv.nil?
|
54
|
-
warn(
|
54
|
+
warn("attr_encrypted() no longer allows a default value for option `random_iv`. Add `random_iv: false` if it is required.")
|
55
55
|
end
|
56
56
|
|
57
57
|
attributes.each do |attribute|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "openssl"
|
2
2
|
module SymmetricEncryption
|
3
3
|
# Hold all information related to encryption keys
|
4
4
|
# as well as encrypt and decrypt data using those keys.
|
@@ -12,7 +12,7 @@ module SymmetricEncryption
|
|
12
12
|
attr_writer :key
|
13
13
|
|
14
14
|
# Returns [Cipher] from a cipher config instance.
|
15
|
-
def self.from_config(cipher_name:
|
15
|
+
def self.from_config(cipher_name: "aes-256-cbc",
|
16
16
|
version: 0,
|
17
17
|
always_add_header: true,
|
18
18
|
encoding: :base64strict,
|
@@ -72,7 +72,7 @@ module SymmetricEncryption
|
|
72
72
|
# Default: true
|
73
73
|
def initialize(key:,
|
74
74
|
iv: nil,
|
75
|
-
cipher_name:
|
75
|
+
cipher_name: "aes-256-cbc",
|
76
76
|
version: 0,
|
77
77
|
always_add_header: true,
|
78
78
|
encoding: :base64strict)
|
@@ -84,7 +84,9 @@ module SymmetricEncryption
|
|
84
84
|
@version = version.to_i
|
85
85
|
@always_add_header = always_add_header
|
86
86
|
|
87
|
-
|
87
|
+
if (@version > 255) || @version.negative?
|
88
|
+
raise(ArgumentError, "Cipher version has a valid range of 0 to 255. #{@version} is too high, or negative")
|
89
|
+
end
|
88
90
|
end
|
89
91
|
|
90
92
|
# Change the encoding
|
@@ -167,7 +169,9 @@ module SymmetricEncryption
|
|
167
169
|
decrypted = binary_decrypt(decoded)
|
168
170
|
|
169
171
|
# Try to force result to UTF-8 encoding, but if it is not valid, force it back to Binary
|
170
|
-
|
172
|
+
unless decrypted.force_encoding(SymmetricEncryption::UTF8_ENCODING).valid_encoding?
|
173
|
+
decrypted.force_encoding(SymmetricEncryption::BINARY_ENCODING)
|
174
|
+
end
|
171
175
|
|
172
176
|
decrypted
|
173
177
|
end
|
@@ -180,7 +184,7 @@ module SymmetricEncryption
|
|
180
184
|
#
|
181
185
|
# Returned string is UTF8 encoded except for encoding :none
|
182
186
|
def encode(binary_string)
|
183
|
-
return binary_string if binary_string.nil? || (binary_string ==
|
187
|
+
return binary_string if binary_string.nil? || (binary_string == "")
|
184
188
|
|
185
189
|
encoder.encode(binary_string)
|
186
190
|
end
|
@@ -190,7 +194,7 @@ module SymmetricEncryption
|
|
190
194
|
#
|
191
195
|
# Returned string is Binary encoded
|
192
196
|
def decode(encoded_string)
|
193
|
-
return encoded_string if encoded_string.nil? || (encoded_string ==
|
197
|
+
return encoded_string if encoded_string.nil? || (encoded_string == "")
|
194
198
|
|
195
199
|
encoder.decode(encoded_string)
|
196
200
|
end
|
@@ -316,8 +320,8 @@ module SymmetricEncryption
|
|
316
320
|
|
317
321
|
openssl_cipher = ::OpenSSL::Cipher.new(header.cipher_name || cipher_name)
|
318
322
|
openssl_cipher.decrypt
|
319
|
-
openssl_cipher.key
|
320
|
-
if (iv
|
323
|
+
openssl_cipher.key = header.key || @key
|
324
|
+
if (iv = header.iv || @iv)
|
321
325
|
openssl_cipher.iv = iv
|
322
326
|
end
|
323
327
|
result = openssl_cipher.update(data)
|
@@ -327,7 +331,7 @@ module SymmetricEncryption
|
|
327
331
|
|
328
332
|
# Returns the magic header after applying the encoding in this cipher
|
329
333
|
def encoded_magic_header
|
330
|
-
@encoded_magic_header ||= encoder.encode(SymmetricEncryption::Header::MAGIC_HEADER).delete(
|
334
|
+
@encoded_magic_header ||= encoder.encode(SymmetricEncryption::Header::MAGIC_HEADER).delete("=").strip
|
331
335
|
end
|
332
336
|
|
333
337
|
# Returns [String] object represented as a string, filtering out the key
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "optparse"
|
2
|
+
require "fileutils"
|
3
3
|
module SymmetricEncryption
|
4
4
|
class CLI
|
5
5
|
attr_reader :key_path, :app_name, :encrypt, :config_file_path,
|
@@ -16,11 +16,11 @@ module SymmetricEncryption
|
|
16
16
|
|
17
17
|
def initialize(argv)
|
18
18
|
@version = current_version
|
19
|
-
@environment = ENV[
|
20
|
-
@config_file_path = File.expand_path(ENV[
|
21
|
-
@app_name =
|
19
|
+
@environment = ENV["SYMMETRIC_ENCRYPTION_ENV"] || ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
|
20
|
+
@config_file_path = File.expand_path(ENV["SYMMETRIC_ENCRYPTION_CONFIG"] || "config/symmetric-encryption.yml")
|
21
|
+
@app_name = "symmetric-encryption"
|
22
22
|
@key_path = "#{ENV['HOME']}/.symmetric-encryption"
|
23
|
-
@cipher_name =
|
23
|
+
@cipher_name = "aes-256-cbc"
|
24
24
|
@rolling_deploy = false
|
25
25
|
@prompt = false
|
26
26
|
@show_version = false
|
@@ -34,7 +34,7 @@ module SymmetricEncryption
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def run!
|
37
|
-
raise(ArgumentError,
|
37
|
+
raise(ArgumentError, "Cannot cleanup keys and rotate keys at the same time") if cleanup_keys && rotate_keys
|
38
38
|
|
39
39
|
if show_version
|
40
40
|
puts "Symmetric Encryption v#{VERSION}"
|
@@ -70,7 +70,7 @@ module SymmetricEncryption
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def parser
|
73
|
-
@parser
|
73
|
+
@parser ||= OptionParser.new do |opts|
|
74
74
|
opts.banner = <<~BANNER
|
75
75
|
Symmetric Encryption v#{VERSION}
|
76
76
|
|
@@ -83,113 +83,113 @@ module SymmetricEncryption
|
|
83
83
|
symmetric-encryption [options]
|
84
84
|
BANNER
|
85
85
|
|
86
|
-
opts.on
|
86
|
+
opts.on "-e", "--encrypt [FILE_NAME]", "Encrypt a file, or read from stdin if no file name is supplied." do |file_name|
|
87
87
|
@encrypt = file_name || STDIN
|
88
88
|
end
|
89
89
|
|
90
|
-
opts.on
|
90
|
+
opts.on "-d", "--decrypt [FILE_NAME]", "Decrypt a file, or read from stdin if no file name is supplied." do |file_name|
|
91
91
|
@decrypt = file_name || STDIN
|
92
92
|
end
|
93
93
|
|
94
|
-
opts.on
|
94
|
+
opts.on "-o", "--output FILE_NAME", "Write encrypted or decrypted file to this file, otherwise output goes to stdout." do |file_name|
|
95
95
|
@output_file_name = file_name
|
96
96
|
end
|
97
97
|
|
98
|
-
opts.on
|
98
|
+
opts.on "-P", "--prompt", "When encrypting or decrypting, prompt for a string encrypt or decrypt." do
|
99
99
|
@prompt = true
|
100
100
|
end
|
101
101
|
|
102
|
-
opts.on
|
102
|
+
opts.on "-z", "--compress", "Compress encrypted output file. [Default for encrypting files]" do
|
103
103
|
@compress = true
|
104
104
|
end
|
105
105
|
|
106
|
-
opts.on
|
106
|
+
opts.on "-Z", "--no-compress", "Does not compress the output file. [Default for encrypting strings]" do
|
107
107
|
@compress = false
|
108
108
|
end
|
109
109
|
|
110
|
-
opts.on
|
110
|
+
opts.on "-E", "--env ENVIRONMENT", "Environment to use in the config file. Default: SYMMETRIC_ENCRYPTION_ENV || RACK_ENV || RAILS_ENV || 'development'" do |environment|
|
111
111
|
@environment = environment
|
112
112
|
end
|
113
113
|
|
114
|
-
opts.on
|
114
|
+
opts.on "-c", "--config CONFIG_FILE_PATH", "File name & path to the Symmetric Encryption configuration file. Default: config/symmetric-encryption.yml or Env var: `SYMMETRIC_ENCRYPTION_CONFIG`" do |path|
|
115
115
|
@config_file_path = path
|
116
116
|
end
|
117
117
|
|
118
|
-
opts.on
|
118
|
+
opts.on "-m", "--migrate", "Migrate configuration file to new format." do
|
119
119
|
@migrate = true
|
120
120
|
end
|
121
121
|
|
122
|
-
opts.on
|
123
|
-
@re_encrypt = pattern ||
|
122
|
+
opts.on "-r", "--re-encrypt [PATTERN]", 'ReEncrypt all files matching the pattern. Default: "**/*.{yml,rb}"' do |pattern|
|
123
|
+
@re_encrypt = pattern || "**/*.{yml,rb}"
|
124
124
|
end
|
125
125
|
|
126
|
-
opts.on
|
126
|
+
opts.on "-n", "--new-password [SIZE]", "Generate a new random password using only characters that are URL-safe base64. Default size is 22." do |size|
|
127
127
|
@random_password = (size || 22).to_i
|
128
128
|
end
|
129
129
|
|
130
|
-
opts.on
|
130
|
+
opts.on "-g", "--generate", "Generate a new configuration file and encryption keys for every environment." do |config|
|
131
131
|
@generate = config
|
132
132
|
end
|
133
133
|
|
134
|
-
opts.on
|
135
|
-
@keystore = (keystore ||
|
134
|
+
opts.on "-s", "--keystore heroku|environment|file|aws|gcp", "Which keystore to use during generation or re-encryption." do |keystore|
|
135
|
+
@keystore = (keystore || "file").downcase.to_sym
|
136
136
|
end
|
137
137
|
|
138
|
-
opts.on
|
139
|
-
@regions = regions.to_s.split(
|
138
|
+
opts.on "-B", "--regions [us-east-1,us-east-2,us-west-1,us-west-2]", "AWS KMS Regions to encrypt data key with." do |regions|
|
139
|
+
@regions = regions.to_s.split(",").collect(&:strip) if regions
|
140
140
|
end
|
141
141
|
|
142
|
-
opts.on
|
142
|
+
opts.on "-K", "--key-path KEY_PATH", "Output path in which to write generated key files. Default: ~/.symmetric-encryption" do |path|
|
143
143
|
@key_path = path
|
144
144
|
end
|
145
145
|
|
146
|
-
opts.on
|
146
|
+
opts.on "-a", "--app-name NAME", "Application name to use when generating a new configuration. Default: symmetric-encryption" do |name|
|
147
147
|
@app_name = name
|
148
148
|
end
|
149
149
|
|
150
|
-
opts.on
|
151
|
-
@environments = environments.split(
|
150
|
+
opts.on "-S", "--environments ENVIRONMENTS", "Comma separated list of environments for which to generate the config file. Default: development,test,release,production" do |environments|
|
151
|
+
@environments = environments.split(",").collect(&:strip).collect(&:to_sym)
|
152
152
|
end
|
153
153
|
|
154
|
-
opts.on
|
154
|
+
opts.on "-C", "--cipher-name NAME", "Name of the cipher to use when generating a new config file, or when rotating keys. Default: aes-256-cbc" do |name|
|
155
155
|
@cipher_name = name
|
156
156
|
end
|
157
157
|
|
158
|
-
opts.on
|
158
|
+
opts.on "-R", "--rotate-keys", "Generates a new encryption key version, encryption key files, and updates the configuration file." do
|
159
159
|
@rotate_keys = true
|
160
160
|
end
|
161
161
|
|
162
|
-
opts.on
|
162
|
+
opts.on "-U", "--rotate-kek", "Replace the existing key encrypting keys only, the data encryption key is not changed, and updates the configuration file." do
|
163
163
|
@rotate_kek = true
|
164
164
|
end
|
165
165
|
|
166
|
-
opts.on
|
166
|
+
opts.on "-D", "--rolling-deploy", "During key rotation, support a rolling deploy by placing the new key second in the list so that it is not activated yet." do
|
167
167
|
@rolling_deploy = true
|
168
168
|
end
|
169
169
|
|
170
|
-
opts.on
|
170
|
+
opts.on "-A", "--activate-key", "Activates the key by moving the key with the highest version to the top." do
|
171
171
|
@activate_key = true
|
172
172
|
end
|
173
173
|
|
174
|
-
opts.on
|
174
|
+
opts.on "-X", "--cleanup-keys", "Removes all encryption keys, except the one with the highest version from the configuration file." do
|
175
175
|
@cleanup_keys = true
|
176
176
|
end
|
177
177
|
|
178
|
-
opts.on
|
178
|
+
opts.on "-V", "--key-version NUMBER", "Encryption key version to use when encrypting or re-encrypting. Default: (Current global version)." do |number|
|
179
179
|
@version = number.to_i
|
180
180
|
end
|
181
181
|
|
182
|
-
opts.on
|
182
|
+
opts.on "-L", "--ciphers", "List available OpenSSL ciphers." do
|
183
183
|
puts "OpenSSL v#{OpenSSL::VERSION}. Available Ciphers:"
|
184
184
|
puts OpenSSL::Cipher.ciphers.join("\n")
|
185
185
|
exit
|
186
186
|
end
|
187
187
|
|
188
|
-
opts.on
|
188
|
+
opts.on "-v", "--version", "Display Symmetric Encryption version." do
|
189
189
|
@show_version = true
|
190
190
|
end
|
191
191
|
|
192
|
-
opts.on(
|
192
|
+
opts.on("-h", "--help", "Prints this help.") do
|
193
193
|
puts opts
|
194
194
|
exit
|
195
195
|
end
|
@@ -212,7 +212,7 @@ module SymmetricEncryption
|
|
212
212
|
|
213
213
|
config_file_does_not_exist!
|
214
214
|
self.environments ||= %i[development test release production]
|
215
|
-
args
|
215
|
+
args = {
|
216
216
|
app_name: app_name,
|
217
217
|
environments: environments,
|
218
218
|
cipher_name: cipher_name
|
@@ -255,7 +255,7 @@ module SymmetricEncryption
|
|
255
255
|
next if environments && !environments.include?(env.to_sym)
|
256
256
|
next unless ciphers = cfg[:ciphers]
|
257
257
|
|
258
|
-
highest
|
258
|
+
highest = ciphers.max_by { |i| i[:version] }
|
259
259
|
ciphers.clear
|
260
260
|
ciphers << highest
|
261
261
|
end
|
@@ -270,7 +270,7 @@ module SymmetricEncryption
|
|
270
270
|
next if environments && !environments.include?(env.to_sym)
|
271
271
|
next unless ciphers = cfg[:ciphers]
|
272
272
|
|
273
|
-
highest
|
273
|
+
highest = ciphers.max_by { |i| i[:version] }
|
274
274
|
ciphers.delete(highest)
|
275
275
|
ciphers.unshift(highest)
|
276
276
|
end
|
@@ -289,22 +289,22 @@ module SymmetricEncryption
|
|
289
289
|
|
290
290
|
def decrypt_string
|
291
291
|
begin
|
292
|
-
require
|
292
|
+
require "highline"
|
293
293
|
rescue LoadError
|
294
294
|
puts("\nPlease install gem highline before using the command line task to decrypt an entered string.\n gem install \"highline\"\n\n")
|
295
295
|
exit(-2)
|
296
296
|
end
|
297
297
|
|
298
|
-
encrypted = HighLine.new.ask(
|
298
|
+
encrypted = HighLine.new.ask("Enter the value to decrypt:")
|
299
299
|
text = SymmetricEncryption.cipher(version).decrypt(encrypted)
|
300
300
|
|
301
301
|
puts("\n\nEncrypted: #{encrypted}")
|
302
|
-
output_file_name ? File.open(output_file_name,
|
302
|
+
output_file_name ? File.open(output_file_name, "wb") { |f| f << text } : puts("Decrypted: #{text}\n\n")
|
303
303
|
end
|
304
304
|
|
305
305
|
def encrypt_string
|
306
306
|
begin
|
307
|
-
require
|
307
|
+
require "highline"
|
308
308
|
rescue LoadError
|
309
309
|
puts("\nPlease install gem highline before using the command line task to encrypt an entered string.\n gem install \"highline\"\n\n")
|
310
310
|
exit(-2)
|
@@ -313,14 +313,14 @@ module SymmetricEncryption
|
|
313
313
|
value2 = 0
|
314
314
|
|
315
315
|
while value1 != value2
|
316
|
-
value1 = HighLine.new.ask(
|
317
|
-
value2 = HighLine.new.ask(
|
316
|
+
value1 = HighLine.new.ask("Enter the value to encrypt:") { |q| q.echo = "*" }
|
317
|
+
value2 = HighLine.new.ask("Re-enter the value to encrypt:") { |q| q.echo = "*" }
|
318
318
|
|
319
|
-
puts(
|
319
|
+
puts("Values do not match, please try again") if value1 != value2
|
320
320
|
end
|
321
321
|
compress = false if compress.nil?
|
322
322
|
encrypted = SymmetricEncryption.cipher(version).encrypt(value1, compress: compress)
|
323
|
-
output_file_name ? File.open(output_file_name,
|
323
|
+
output_file_name ? File.open(output_file_name, "wb") { |f| f << encrypted } : puts("\n\nEncrypted: #{encrypted}\n\n")
|
324
324
|
end
|
325
325
|
|
326
326
|
def gen_random_password(size)
|
@@ -328,7 +328,7 @@ module SymmetricEncryption
|
|
328
328
|
puts("\nGenerated Password: #{p}")
|
329
329
|
encrypted = SymmetricEncryption.encrypt(p)
|
330
330
|
puts("Encrypted: #{encrypted}\n\n")
|
331
|
-
File.open(output_file_name,
|
331
|
+
File.open(output_file_name, "wb") { |f| f << encrypted } if output_file_name
|
332
332
|
end
|
333
333
|
|
334
334
|
def current_version
|