encrypt_env 1.0.1 → 1.0.4
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/lib/encrypt_env.rb +8 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c78b9777eaf2d1de712e3e14e0eb69aeaeb4126c658831e093fd3d009a74e1
|
4
|
+
data.tar.gz: 602f65454d578bedeb4afcb7cab5e8bdd15fec83804a7ca638e31eceba512aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51bbe5039a0e27aaad62b0504cf9ae9a316ffd0e4c33e02b4559541901fe9691cc077a9e4a304e42ac90fe146747a66cdd221a5b97c02dd283a92065f23063d8
|
7
|
+
data.tar.gz: b84ca2e78d722954cd6f67614d6290101c0688856497086bbd091cfce6424d7baa6f426464682a5ffbbd1cae1edba262756e698aa8bd5f7bc48a30d8e3989fcf
|
data/lib/encrypt_env.rb
CHANGED
@@ -7,6 +7,7 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
7
7
|
require 'tempfile'
|
8
8
|
|
9
9
|
# gem 'encrypt_env'
|
10
|
+
# rubocop: disable all
|
10
11
|
class EncryptEnv
|
11
12
|
private_class_method def self.master_key
|
12
13
|
key = File.read("#{@path_root}/config/master.key")
|
@@ -17,7 +18,7 @@ class EncryptEnv
|
|
17
18
|
encrypted = raw_data.slice(0, raw_data.length - 28)
|
18
19
|
iv = raw_data.slice(raw_data.length - 28, 12)
|
19
20
|
tag = raw_data.slice(raw_data.length - 16, 16)
|
20
|
-
{ encrypted: encrypted, iv: iv, tag: tag }
|
21
|
+
return { encrypted: encrypted, iv: iv, tag: tag }
|
21
22
|
end
|
22
23
|
|
23
24
|
private_class_method def self.encrypt(content)
|
@@ -27,7 +28,7 @@ class EncryptEnv
|
|
27
28
|
iv = cipher.random_iv
|
28
29
|
encrypted = cipher.update(content) + cipher.final
|
29
30
|
tag = cipher.auth_tag
|
30
|
-
hex_string = (encrypted + iv + tag).
|
31
|
+
hex_string = (encrypted + iv + tag).unpack('H*').first
|
31
32
|
File.open("#{@path_root}/config/secrets.yml.enc", 'w') { |file| file.write(hex_string) }
|
32
33
|
end
|
33
34
|
|
@@ -35,12 +36,12 @@ class EncryptEnv
|
|
35
36
|
decipher = OpenSSL::Cipher.new('aes-128-gcm')
|
36
37
|
decipher.decrypt
|
37
38
|
hex_string = File.read("#{@path_root}/config/secrets.yml.enc")
|
38
|
-
|
39
|
-
decipher.iv =
|
39
|
+
data = data_decrypt([hex_string].pack('H*'))
|
40
|
+
decipher.iv = data[:iv]
|
40
41
|
decipher.key = master_key
|
41
|
-
decipher.auth_tag =
|
42
|
+
decipher.auth_tag = data[:tag]
|
42
43
|
|
43
|
-
decipher.update(
|
44
|
+
decipher.update(data[:encrypted]) + decipher.final
|
44
45
|
end
|
45
46
|
|
46
47
|
private_class_method def self.path_root
|
@@ -58,7 +59,7 @@ class EncryptEnv
|
|
58
59
|
@secret_file = File.expand_path("#{@path_root}/config/secrets.yml")
|
59
60
|
key = OpenSSL::Random.random_bytes(16)
|
60
61
|
# save key in master.key file
|
61
|
-
File.open("#{@path_root}/config/master.key", 'w') { |file| file.write(key.
|
62
|
+
File.open("#{@path_root}/config/master.key", 'w') { |file| file.write(key.unpack('H*').first) }
|
62
63
|
encrypt(File.read(@secret_file))
|
63
64
|
end
|
64
65
|
|