secret-keeper 0.0.0 → 0.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/secret-keeper.rb +72 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc5383502f63aed8ab7bdf8f82dd145b07850511
|
4
|
+
data.tar.gz: a1be94c83ef92b0a858c8abbb849db032c1f3de4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c82d208c39dbb2d0208598cbac91c570b9129289c2316bafac0498de94e2cc434c3de96fca9f91f9f17d89e4314d8bbfab5703cf1092cd6df330a6f2c82be743
|
7
|
+
data.tar.gz: e8960a0060f1783f7502a537a3c8dd92e5efac9059b288f6d3050490b8fccbc71f6fbf1b770b4ab47f2607315bb12fc17ba926765fc7eed64c4a8afb92511ae9
|
data/lib/secret-keeper.rb
CHANGED
@@ -1,5 +1,77 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'yaml'
|
3
|
+
|
1
4
|
class SecretKeeper
|
2
5
|
def self.hi
|
3
6
|
puts '...(said nothing)'
|
4
7
|
end
|
8
|
+
|
9
|
+
def self.encrypt_files
|
10
|
+
puts 'Encrypting...'
|
11
|
+
sk = SecretKeeper.new
|
12
|
+
sk.tasks.each do |task|
|
13
|
+
from = task['encrypt_from']
|
14
|
+
to = task['encrypt_to']
|
15
|
+
|
16
|
+
result = sk.encrypt_file(from, to)
|
17
|
+
puts " * #{from} --> #{to}, #{result}"
|
18
|
+
end
|
19
|
+
puts 'Done!'
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.decrypt_files
|
23
|
+
puts 'Decrypting...'
|
24
|
+
sk = SecretKeeper.new
|
25
|
+
sk.tasks.each do |task|
|
26
|
+
from = task['decrypt_from'] || task['encrypt_to']
|
27
|
+
to = task['decrypt_to'] || task['encrypt_from']
|
28
|
+
|
29
|
+
result = sk.decrypt_file(from, to)
|
30
|
+
puts " * #{from} --> #{to}, #{result}"
|
31
|
+
end
|
32
|
+
puts 'Done!'
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
env = ENV['RAILS_ENV'] || 'development'
|
37
|
+
string = File.open('config/secret-keeper.yml', 'rb') { |f| f.read }
|
38
|
+
config = YAML.load(string)[env]
|
39
|
+
@password = ENV['OPENSSL_PASS'] || 'DEFAULT-PASSWORD'
|
40
|
+
@tasks = config['tasks']
|
41
|
+
@using_cipher = OpenSSL::Cipher.new(config['cipher'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def tasks
|
45
|
+
@tasks
|
46
|
+
end
|
47
|
+
|
48
|
+
def encrypt_file(from_file, to_file)
|
49
|
+
encrypted = File.open(from_file, 'rb') { |f| encrypt(f.read) }
|
50
|
+
File.open(to_file, 'w:ASCII-8BIT') { |f| f.write(encrypted) }
|
51
|
+
:ok
|
52
|
+
rescue => e
|
53
|
+
"fail: #{e}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def decrypt_file(from_file, to_file)
|
57
|
+
decrypted = File.open(from_file, 'rb') { |f| decrypt(f.read) }
|
58
|
+
File.open(to_file, 'w') { |f| f.write(decrypted) }
|
59
|
+
:ok
|
60
|
+
rescue => e
|
61
|
+
"fail: #{e}"
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def encrypt(data)
|
67
|
+
cipher = @using_cipher.encrypt
|
68
|
+
cipher.key = Digest::SHA1.hexdigest(@password)
|
69
|
+
cipher.update(data) + cipher.final
|
70
|
+
end
|
71
|
+
|
72
|
+
def decrypt(data)
|
73
|
+
cipher = @using_cipher.decrypt
|
74
|
+
cipher.key = Digest::SHA1.hexdigest(@password)
|
75
|
+
cipher.update(data) + cipher.final
|
76
|
+
end
|
5
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret-keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Lee
|
@@ -40,5 +40,5 @@ rubyforge_project:
|
|
40
40
|
rubygems_version: 2.6.14
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
|
-
summary:
|
43
|
+
summary: Keep all your secret files within openssl
|
44
44
|
test_files: []
|