simple_crypt 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_crypt.rb +11 -7
- data/lib/simple_crypt/secret.rb +0 -18
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ef4c33991428c84237551c5d7eecf83dc17f21579f5f85027f35f5eb89b2979
|
4
|
+
data.tar.gz: 3e4b223d1ecd2cd71c6df841c14a5a84f9d447353fe6c779774f891d6abc8148
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7418353c839a55671ed4dd865c20f0dc675cd27f236f216b9ef1b6349a9a408c7aa705aee60c4d3b996bca550ea12b77bca5fcbdb4ffaa84ab097a7c3eff658f
|
7
|
+
data.tar.gz: d297d9643c97b3a1d1237a38fe65b6dc746dd797e0b3a8ec373f42a7dc9db68e82227a6e3332a43f96d0913d8c9b455b89a46c58a7b19744d56e76a130181c07
|
data/lib/simple_crypt.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'openssl'
|
3
3
|
require 'securerandom'
|
4
|
-
|
4
|
+
require_relative 'simple_crypt/secret'
|
5
5
|
|
6
6
|
# encrypts and stores and decrypts secrets
|
7
7
|
module SimpleCrypt
|
8
8
|
def self.encrypt(data, pwd)
|
9
|
-
|
10
|
-
|
11
|
-
iv = cipher.random_iv
|
12
|
-
salt = OpenSSL::Random.random_bytes 16
|
9
|
+
iv = OpenSSL::Random.random_bytes(12)
|
10
|
+
salt = OpenSSL::Random.random_bytes(16)
|
13
11
|
auth_data = SecureRandom.urlsafe_base64(16)
|
14
12
|
key = gen_key(pwd, salt)
|
13
|
+
|
14
|
+
cipher = OpenSSL::Cipher.new('aes-256-gcm')
|
15
|
+
cipher.encrypt
|
16
|
+
cipher.iv = iv
|
15
17
|
cipher.key = key
|
16
18
|
cipher.auth_data = auth_data
|
19
|
+
|
17
20
|
sec = SimpleCrypt::Secret.new
|
18
21
|
sec.secret_data = Base64.strict_encode64(cipher.update(data) + cipher.final)
|
19
22
|
sec.iv = Base64.strict_encode64(iv)
|
@@ -26,13 +29,14 @@ module SimpleCrypt
|
|
26
29
|
def self.decrypt(secret, pwd)
|
27
30
|
salt = Base64.strict_decode64(secret.salt)
|
28
31
|
secret_data = Base64.strict_decode64(secret.secret_data)
|
32
|
+
|
29
33
|
decipher = OpenSSL::Cipher.new('aes-256-gcm')
|
30
34
|
decipher.decrypt
|
31
35
|
decipher.iv = Base64.strict_decode64(secret.iv)
|
32
|
-
key = gen_key(pwd, salt)
|
33
|
-
decipher.key = key
|
36
|
+
decipher.key = gen_key(pwd, salt)
|
34
37
|
decipher.auth_tag = Base64.strict_decode64(secret.auth_tag)
|
35
38
|
decipher.auth_data = secret.auth_data
|
39
|
+
|
36
40
|
begin
|
37
41
|
decrypted = decipher.update(secret_data) + decipher.final
|
38
42
|
return decrypted
|
data/lib/simple_crypt/secret.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
1
|
# stores secret info as a class
|
4
2
|
module SimpleCrypt
|
5
3
|
class Secret
|
@@ -12,21 +10,5 @@ module SimpleCrypt
|
|
12
10
|
@auth_tag = auth_tag
|
13
11
|
@auth_data = auth_data
|
14
12
|
end
|
15
|
-
|
16
|
-
def to_json
|
17
|
-
JSON.generate(Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }])
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.load(json)
|
21
|
-
data = JSON.parse(json)
|
22
|
-
s = new(
|
23
|
-
data['@secret_data'],
|
24
|
-
data['@iv'],
|
25
|
-
data['@salt'],
|
26
|
-
data['@auth_tag'],
|
27
|
-
data['@auth_data']
|
28
|
-
)
|
29
|
-
s
|
30
|
-
end
|
31
13
|
end
|
32
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_crypt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Silverman
|
@@ -18,10 +18,11 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/simple_crypt.rb
|
20
20
|
- lib/simple_crypt/secret.rb
|
21
|
-
homepage:
|
21
|
+
homepage: https://github.com/nckslvrmn/simple_crypt
|
22
22
|
licenses:
|
23
23
|
- GPL-3.0
|
24
|
-
metadata:
|
24
|
+
metadata:
|
25
|
+
source_code_uri: https://github.com/nckslvrmn/simple_crypt
|
25
26
|
post_install_message:
|
26
27
|
rdoc_options: []
|
27
28
|
require_paths:
|