lite-encryption 1.0.0 → 1.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 +4 -4
- data/.rubocop.yml +17 -3
- data/.travis.yml +1 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +101 -85
- data/README.md +49 -13
- data/lib/generators/lite/encryption/templates/install.rb +3 -2
- data/lib/lite/encryption.rb +17 -1
- data/lib/lite/encryption/configuration.rb +4 -5
- data/lib/lite/encryption/helpers/class_methods.rb +18 -0
- data/lib/lite/encryption/key.rb +40 -0
- data/lib/lite/encryption/message.rb +15 -27
- data/lib/lite/encryption/schemes/deterministic.rb +36 -0
- data/lib/lite/encryption/schemes/non_deterministic.rb +30 -0
- data/lib/lite/encryption/version.rb +1 -1
- data/lite-encryption.gemspec +4 -3
- metadata +25 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5f2a37b612cb9d2f2fe5a941af941b9d0423b9ce1232887830d08a5f4fa4bc0
|
|
4
|
+
data.tar.gz: e69ea20e36b30f0adcc60f753a117f3f8bc6825a1e9e2109fef1528bc993c951
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b81e82c8885e661eb17f38d584874e7a59297e6f0f55f9f32cfbf73678516d16f7aaec3fa8d0f81534da87c2b62e55a799396c402b4bea40313640b719c0374
|
|
7
|
+
data.tar.gz: 6d1b39740a256ae0df3446895b818f04f7d48c83981f8af1be7236911694faaf2cc618a11a88de4ba5d0f404e27f13ac1eed78518612755ee35ac341edb63709
|
data/.rubocop.yml
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
require:
|
|
2
2
|
- rubocop-performance
|
|
3
|
+
- rubocop-rake
|
|
3
4
|
- rubocop-rspec
|
|
4
5
|
AllCops:
|
|
5
|
-
TargetRubyVersion:
|
|
6
|
+
TargetRubyVersion: 3.0
|
|
7
|
+
NewCops: enable
|
|
6
8
|
DisplayCopNames: true
|
|
7
9
|
DisplayStyleGuide: true
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
Gemspec/RequiredRubyVersion:
|
|
11
|
+
Enabled: false
|
|
12
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
|
13
|
+
Enabled: true
|
|
10
14
|
Layout/EmptyLinesAroundBlockBody:
|
|
11
15
|
Exclude:
|
|
12
16
|
- 'spec/**/**/*'
|
|
@@ -14,6 +18,14 @@ Layout/EmptyLinesAroundClassBody:
|
|
|
14
18
|
EnforcedStyle: empty_lines_except_namespace
|
|
15
19
|
Layout/EmptyLinesAroundModuleBody:
|
|
16
20
|
EnforcedStyle: empty_lines_except_namespace
|
|
21
|
+
Layout/LineLength:
|
|
22
|
+
Max: 100
|
|
23
|
+
Layout/SpaceAroundMethodCallOperator:
|
|
24
|
+
Enabled: true
|
|
25
|
+
Lint/RaiseException:
|
|
26
|
+
Enabled: true
|
|
27
|
+
Lint/StructNewOverride:
|
|
28
|
+
Enabled: true
|
|
17
29
|
Metrics/BlockLength:
|
|
18
30
|
Exclude:
|
|
19
31
|
- 'spec/**/**/*'
|
|
@@ -22,6 +34,8 @@ Metrics/ModuleLength:
|
|
|
22
34
|
Enabled: false
|
|
23
35
|
RSpec/MultipleExpectations:
|
|
24
36
|
Enabled: false
|
|
37
|
+
Style/ArgumentsForwarding:
|
|
38
|
+
Enabled: false
|
|
25
39
|
Style/Documentation:
|
|
26
40
|
Enabled: false
|
|
27
41
|
Style/ExpandPathArguments:
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.2.0] - 2021-07-19
|
|
10
|
+
### Added
|
|
11
|
+
- Added Ruby 3.0 support
|
|
12
|
+
|
|
13
|
+
## [1.1.0] - 2021-04-12
|
|
14
|
+
### Added
|
|
15
|
+
- Added deterministic encryption
|
|
16
|
+
### Changed
|
|
17
|
+
- Update configuration methods
|
|
18
|
+
|
|
19
|
+
## [1.0.1] - 2020-07-03
|
|
20
|
+
### Added
|
|
21
|
+
- Added Ruby 2.7 support
|
|
22
|
+
|
|
23
|
+
## [1.0.1] - 2019-08-26
|
|
24
|
+
### Added
|
|
25
|
+
- Key class for key generation
|
|
26
|
+
### Changed
|
|
27
|
+
- Update initializer file
|
|
28
|
+
|
|
9
29
|
## [1.0.0] - 2019-08-24
|
|
10
30
|
### Added
|
|
11
31
|
- Initial project version
|
data/Gemfile.lock
CHANGED
|
@@ -1,123 +1,138 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lite-encryption (1.
|
|
4
|
+
lite-encryption (1.2.0)
|
|
5
5
|
activesupport
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionpack (6.
|
|
11
|
-
actionview (= 6.
|
|
12
|
-
activesupport (= 6.
|
|
13
|
-
rack (~> 2.0)
|
|
10
|
+
actionpack (6.1.4)
|
|
11
|
+
actionview (= 6.1.4)
|
|
12
|
+
activesupport (= 6.1.4)
|
|
13
|
+
rack (~> 2.0, >= 2.0.9)
|
|
14
14
|
rack-test (>= 0.6.3)
|
|
15
15
|
rails-dom-testing (~> 2.0)
|
|
16
16
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
17
|
-
actionview (6.
|
|
18
|
-
activesupport (= 6.
|
|
17
|
+
actionview (6.1.4)
|
|
18
|
+
activesupport (= 6.1.4)
|
|
19
19
|
builder (~> 3.1)
|
|
20
20
|
erubi (~> 1.4)
|
|
21
21
|
rails-dom-testing (~> 2.0)
|
|
22
22
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
23
|
-
activemodel (6.
|
|
24
|
-
activesupport (= 6.
|
|
25
|
-
activerecord (6.
|
|
26
|
-
activemodel (= 6.
|
|
27
|
-
activesupport (= 6.
|
|
28
|
-
activesupport (6.
|
|
23
|
+
activemodel (6.1.4)
|
|
24
|
+
activesupport (= 6.1.4)
|
|
25
|
+
activerecord (6.1.4)
|
|
26
|
+
activemodel (= 6.1.4)
|
|
27
|
+
activesupport (= 6.1.4)
|
|
28
|
+
activesupport (6.1.4)
|
|
29
29
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
30
|
-
i18n (>=
|
|
31
|
-
minitest (
|
|
32
|
-
tzinfo (~>
|
|
33
|
-
zeitwerk (~> 2.
|
|
34
|
-
ast (2.4.
|
|
35
|
-
builder (3.2.
|
|
30
|
+
i18n (>= 1.6, < 2)
|
|
31
|
+
minitest (>= 5.1)
|
|
32
|
+
tzinfo (~> 2.0)
|
|
33
|
+
zeitwerk (~> 2.3)
|
|
34
|
+
ast (2.4.2)
|
|
35
|
+
builder (3.2.4)
|
|
36
36
|
colorize (0.8.1)
|
|
37
|
-
concurrent-ruby (1.1.
|
|
38
|
-
crass (1.0.
|
|
39
|
-
database_cleaner (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
concurrent-ruby (1.1.9)
|
|
38
|
+
crass (1.0.6)
|
|
39
|
+
database_cleaner (2.0.1)
|
|
40
|
+
database_cleaner-active_record (~> 2.0.0)
|
|
41
|
+
database_cleaner-active_record (2.0.1)
|
|
42
|
+
activerecord (>= 5.a)
|
|
43
|
+
database_cleaner-core (~> 2.0.0)
|
|
44
|
+
database_cleaner-core (2.0.1)
|
|
45
|
+
diff-lcs (1.4.4)
|
|
46
|
+
erubi (1.10.0)
|
|
47
|
+
fasterer (0.9.0)
|
|
43
48
|
colorize (~> 0.7)
|
|
44
|
-
ruby_parser (>= 3.
|
|
49
|
+
ruby_parser (>= 3.14.1)
|
|
45
50
|
generator_spec (0.9.4)
|
|
46
51
|
activesupport (>= 3.0.0)
|
|
47
52
|
railties (>= 3.0.0)
|
|
48
|
-
i18n (1.
|
|
53
|
+
i18n (1.8.10)
|
|
49
54
|
concurrent-ruby (~> 1.0)
|
|
50
|
-
|
|
51
|
-
loofah (2.2.3)
|
|
55
|
+
loofah (2.10.0)
|
|
52
56
|
crass (~> 1.0.2)
|
|
53
57
|
nokogiri (>= 1.5.9)
|
|
54
|
-
method_source (0.
|
|
55
|
-
mini_portile2 (2.
|
|
56
|
-
minitest (5.
|
|
57
|
-
nokogiri (1.
|
|
58
|
-
mini_portile2 (~> 2.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
method_source (1.0.0)
|
|
59
|
+
mini_portile2 (2.5.3)
|
|
60
|
+
minitest (5.14.4)
|
|
61
|
+
nokogiri (1.11.7)
|
|
62
|
+
mini_portile2 (~> 2.5.0)
|
|
63
|
+
racc (~> 1.4)
|
|
64
|
+
parallel (1.20.1)
|
|
65
|
+
parser (3.0.2.0)
|
|
66
|
+
ast (~> 2.4.1)
|
|
67
|
+
racc (1.5.2)
|
|
68
|
+
rack (2.2.3)
|
|
63
69
|
rack-test (1.1.0)
|
|
64
70
|
rack (>= 1.0, < 3)
|
|
65
71
|
rails-dom-testing (2.0.3)
|
|
66
72
|
activesupport (>= 4.2.0)
|
|
67
73
|
nokogiri (>= 1.6)
|
|
68
|
-
rails-html-sanitizer (1.
|
|
69
|
-
loofah (~> 2.
|
|
70
|
-
railties (6.
|
|
71
|
-
actionpack (= 6.
|
|
72
|
-
activesupport (= 6.
|
|
74
|
+
rails-html-sanitizer (1.3.0)
|
|
75
|
+
loofah (~> 2.3)
|
|
76
|
+
railties (6.1.4)
|
|
77
|
+
actionpack (= 6.1.4)
|
|
78
|
+
activesupport (= 6.1.4)
|
|
73
79
|
method_source
|
|
74
|
-
rake (>= 0.
|
|
75
|
-
thor (
|
|
80
|
+
rake (>= 0.13)
|
|
81
|
+
thor (~> 1.0)
|
|
76
82
|
rainbow (3.0.0)
|
|
77
|
-
rake (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
rspec-
|
|
82
|
-
|
|
83
|
-
rspec-
|
|
84
|
-
rspec-
|
|
83
|
+
rake (13.0.6)
|
|
84
|
+
regexp_parser (2.1.1)
|
|
85
|
+
rexml (3.2.5)
|
|
86
|
+
rspec (3.10.0)
|
|
87
|
+
rspec-core (~> 3.10.0)
|
|
88
|
+
rspec-expectations (~> 3.10.0)
|
|
89
|
+
rspec-mocks (~> 3.10.0)
|
|
90
|
+
rspec-core (3.10.1)
|
|
91
|
+
rspec-support (~> 3.10.0)
|
|
92
|
+
rspec-expectations (3.10.1)
|
|
85
93
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
86
|
-
rspec-support (~> 3.
|
|
87
|
-
rspec-mocks (3.
|
|
94
|
+
rspec-support (~> 3.10.0)
|
|
95
|
+
rspec-mocks (3.10.2)
|
|
88
96
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
89
|
-
rspec-support (~> 3.
|
|
90
|
-
rspec-rails (
|
|
91
|
-
actionpack (>=
|
|
92
|
-
activesupport (>=
|
|
93
|
-
railties (>=
|
|
94
|
-
rspec-core (~> 3.
|
|
95
|
-
rspec-expectations (~> 3.
|
|
96
|
-
rspec-mocks (~> 3.
|
|
97
|
-
rspec-support (~> 3.
|
|
98
|
-
rspec-support (3.
|
|
99
|
-
rubocop (
|
|
100
|
-
jaro_winkler (~> 1.5.1)
|
|
97
|
+
rspec-support (~> 3.10.0)
|
|
98
|
+
rspec-rails (5.0.1)
|
|
99
|
+
actionpack (>= 5.2)
|
|
100
|
+
activesupport (>= 5.2)
|
|
101
|
+
railties (>= 5.2)
|
|
102
|
+
rspec-core (~> 3.10)
|
|
103
|
+
rspec-expectations (~> 3.10)
|
|
104
|
+
rspec-mocks (~> 3.10)
|
|
105
|
+
rspec-support (~> 3.10)
|
|
106
|
+
rspec-support (3.10.2)
|
|
107
|
+
rubocop (1.18.3)
|
|
101
108
|
parallel (~> 1.10)
|
|
102
|
-
parser (>=
|
|
109
|
+
parser (>= 3.0.0.0)
|
|
103
110
|
rainbow (>= 2.2.2, < 4.0)
|
|
111
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
112
|
+
rexml
|
|
113
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
|
104
114
|
ruby-progressbar (~> 1.7)
|
|
105
|
-
unicode-display_width (>= 1.4.0, <
|
|
106
|
-
rubocop-
|
|
107
|
-
|
|
108
|
-
rubocop-
|
|
109
|
-
rubocop (>=
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
116
|
+
rubocop-ast (1.8.0)
|
|
117
|
+
parser (>= 3.0.1.1)
|
|
118
|
+
rubocop-performance (1.11.4)
|
|
119
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
120
|
+
rubocop-ast (>= 0.4.0)
|
|
121
|
+
rubocop-rake (0.6.0)
|
|
122
|
+
rubocop (~> 1.0)
|
|
123
|
+
rubocop-rspec (2.4.0)
|
|
124
|
+
rubocop (~> 1.0)
|
|
125
|
+
rubocop-ast (>= 1.1.0)
|
|
126
|
+
ruby-progressbar (1.11.0)
|
|
127
|
+
ruby_parser (3.16.0)
|
|
128
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
|
129
|
+
sexp_processor (4.15.3)
|
|
130
|
+
sqlite3 (1.4.2)
|
|
131
|
+
thor (1.1.0)
|
|
132
|
+
tzinfo (2.0.4)
|
|
133
|
+
concurrent-ruby (~> 1.0)
|
|
134
|
+
unicode-display_width (2.0.0)
|
|
135
|
+
zeitwerk (2.4.2)
|
|
121
136
|
|
|
122
137
|
PLATFORMS
|
|
123
138
|
ruby
|
|
@@ -134,8 +149,9 @@ DEPENDENCIES
|
|
|
134
149
|
rspec-rails
|
|
135
150
|
rubocop
|
|
136
151
|
rubocop-performance
|
|
152
|
+
rubocop-rake
|
|
137
153
|
rubocop-rspec
|
|
138
154
|
sqlite3
|
|
139
155
|
|
|
140
156
|
BUNDLED WITH
|
|
141
|
-
2.
|
|
157
|
+
2.2.24
|
data/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
[](http://badge.fury.io/rb/lite-encryption)
|
|
4
4
|
[](https://travis-ci.org/drexed/lite-encryption)
|
|
5
5
|
|
|
6
|
-
Lite::Encryption is a ActiveSupport::MessageEncryptor
|
|
7
|
-
PORO
|
|
6
|
+
Lite::Encryption is a ActiveSupport::MessageEncryptor and OpenSSL::Cipher::Cipher wrapper libraries
|
|
7
|
+
for encrypting and decrypting PORO object values and model attributes.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -25,6 +25,8 @@ Or install it yourself as:
|
|
|
25
25
|
## Table of Contents
|
|
26
26
|
|
|
27
27
|
* [Configurations](#configurations)
|
|
28
|
+
* [Key](#key)
|
|
29
|
+
* [Schemes](#schemes)
|
|
28
30
|
* [Message](#message)
|
|
29
31
|
* [Attribute](#attribute)
|
|
30
32
|
|
|
@@ -35,26 +37,47 @@ Or install it yourself as:
|
|
|
35
37
|
|
|
36
38
|
```ruby
|
|
37
39
|
Lite::Encryption.configure do |config|
|
|
38
|
-
config.
|
|
39
|
-
config.
|
|
40
|
+
config.encryption_iv = ENV['ENCRYPTION_IV']
|
|
41
|
+
config.encryption_key = ENV['ENCRYPTION_KEY']
|
|
42
|
+
config.encryption_salt = ENV['ENCRYPTION_SALT']
|
|
40
43
|
end
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
## Key
|
|
47
|
+
|
|
48
|
+
Use the following to generate encryption values that you can then add to your
|
|
49
|
+
credentials or ENV variables.
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
Lite::Encryption::Key.generate_iv #=> "\x9C\x9F5<\xA5\x9B\x97\x97\xE2\x1DQ\x05"
|
|
53
|
+
Lite::Encryption::Key.generate_key #=> "y\x0Eo\xC1Gll\x05Qv\x11[\xE1vN8<\xAFxU_\xCB\xD7\x02)0\xC1#\x99\xDD4N"
|
|
54
|
+
Lite::Encryption::Key.generate_password #=> "289b4997f758b31693d3315679d9fa7c"
|
|
55
|
+
Lite::Encryption::Key.generate_salt #=> "\xD2\xBA\x9B\x81@e\x99\x8BN\a7\xC2\x95)f\x97k\xC9EM\xE0x\xFBO\x9BERBD\x85%n"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Schemes
|
|
59
|
+
|
|
60
|
+
The non-deterministic message class is the wrapper class for `ActiveSupport::MessageEncryptor` so
|
|
61
|
+
you can pass it accepted options.
|
|
62
|
+
|
|
63
|
+
The deterministic message class is the wrapper class for `OpenSSL::Cipher::Cipher` so
|
|
64
|
+
you can pass it accepted options.
|
|
45
65
|
|
|
46
|
-
To generate a `secret_key_base`, execute `bundle exec rails secret` in the terminal prompt.
|
|
47
|
-
To generate a `secret_key_salt`, execute the following command in the Rails console prompt:
|
|
48
66
|
```ruby
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
Lite::Encryption::Schemes::NonDeterministic.encrypt('decrypted_text', purpose: 'sec-pur')
|
|
68
|
+
Lite::Encryption::Schemes::NonDeterministic.decrypt('==encrypted_text')
|
|
69
|
+
|
|
70
|
+
# - or -
|
|
71
|
+
|
|
72
|
+
service = Lite::Encryption::Deterministic.new
|
|
73
|
+
|
|
74
|
+
service.encrypt('decrypted_text')
|
|
75
|
+
service.decrypt('==encrypted_text')
|
|
52
76
|
```
|
|
53
77
|
|
|
54
78
|
## Message
|
|
55
79
|
|
|
56
|
-
The message class is the wrapper class for
|
|
57
|
-
accepted options.
|
|
80
|
+
The message class is the wrapper class for both schemes so you can pass it accepted options.
|
|
58
81
|
|
|
59
82
|
```ruby
|
|
60
83
|
Lite::Encryption::Message.encrypt('decrypted_text', purpose: 'sec-pur')
|
|
@@ -66,6 +89,18 @@ service = Lite::Encryption::Message.new
|
|
|
66
89
|
|
|
67
90
|
service.encrypt('decrypted_text', expires_in: 2.hours)
|
|
68
91
|
service.decrypt('==encrypted_text')
|
|
92
|
+
|
|
93
|
+
# - or -
|
|
94
|
+
|
|
95
|
+
Lite::Encryption::Message.encrypt('decrypted_text', deterministic: true)
|
|
96
|
+
Lite::Encryption::Message.decrypt('==encrypted_text', deterministic: true)
|
|
97
|
+
|
|
98
|
+
# - or -
|
|
99
|
+
|
|
100
|
+
service = Lite::Encryption::Message.new
|
|
101
|
+
|
|
102
|
+
service.encrypt('decrypted_text', deterministic: true)
|
|
103
|
+
service.decrypt('==encrypted_text', deterministic: true)
|
|
69
104
|
```
|
|
70
105
|
|
|
71
106
|
## Attribute
|
|
@@ -79,6 +114,7 @@ encrypt and decrypt your values.
|
|
|
79
114
|
class CreditCard < ActiveRecord::Base
|
|
80
115
|
extend Lite::Encryption::Attribute
|
|
81
116
|
|
|
117
|
+
attr_encrypt :name, deterministic: true
|
|
82
118
|
attr_encrypt :number, :cvv, purpose: 'payment-menthod'
|
|
83
119
|
|
|
84
120
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
Lite::Encryption.configure do |config|
|
|
4
|
-
config.
|
|
5
|
-
config.
|
|
4
|
+
config.encryption_iv = ENV['ENCRYPTION_IV']
|
|
5
|
+
config.encryption_key = ENV['ENCRYPTION_KEY']
|
|
6
|
+
config.encryption_salt = ENV['ENCRYPTION_SALT']
|
|
6
7
|
end
|
data/lib/lite/encryption.rb
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
%w[
|
|
3
|
+
%w[key_generator message_encryptor message_verifier].each do |filename|
|
|
4
|
+
require "active_support/#{filename}"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'lite/encryption/version'
|
|
8
|
+
|
|
9
|
+
%w[key configuration].each do |filename|
|
|
10
|
+
require "lite/encryption/#{filename}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require 'lite/encryption/helpers/class_methods'
|
|
14
|
+
|
|
15
|
+
%w[deterministic non_deterministic].each do |filename|
|
|
16
|
+
require "lite/encryption/schemes/#{filename}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
%w[message attribute].each do |filename|
|
|
4
20
|
require "lite/encryption/#{filename}"
|
|
5
21
|
end
|
|
6
22
|
|
|
@@ -5,14 +5,13 @@ module Lite
|
|
|
5
5
|
|
|
6
6
|
class Configuration
|
|
7
7
|
|
|
8
|
-
attr_accessor :
|
|
8
|
+
attr_accessor :encryption_iv, :encryption_key, :encryption_salt
|
|
9
9
|
|
|
10
|
-
# rubocop:disable Metrics/LineLength
|
|
11
10
|
def initialize
|
|
12
|
-
@
|
|
13
|
-
@
|
|
11
|
+
@encryption_iv = Lite::Encryption::Key.generate_iv
|
|
12
|
+
@encryption_key = Lite::Encryption::Key.generate_key
|
|
13
|
+
@encryption_salt = Lite::Encryption::Key.generate_salt
|
|
14
14
|
end
|
|
15
|
-
# rubocop:enable Metrics/LineLength
|
|
16
15
|
|
|
17
16
|
end
|
|
18
17
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lite
|
|
4
|
+
module Encryption
|
|
5
|
+
module Helpers
|
|
6
|
+
module ClassMethods
|
|
7
|
+
|
|
8
|
+
%i[decrypt encrypt].each do |name|
|
|
9
|
+
define_method(name) do |value, opts = {}|
|
|
10
|
+
klass = new
|
|
11
|
+
klass.send(name, value, opts)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Lite
|
|
6
|
+
module Encryption
|
|
7
|
+
class Key
|
|
8
|
+
|
|
9
|
+
CIPHER = OpenSSL::Cipher.new('aes-256-gcm').freeze
|
|
10
|
+
LENGTHS = {
|
|
11
|
+
iv: CIPHER.iv_len,
|
|
12
|
+
key: CIPHER.key_len,
|
|
13
|
+
password: 16,
|
|
14
|
+
salt: CIPHER.key_len
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
|
|
19
|
+
def generate_iv
|
|
20
|
+
SecureRandom.random_bytes(LENGTHS[:iv])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def generate_key
|
|
24
|
+
generator = ActiveSupport::KeyGenerator.new(generate_password)
|
|
25
|
+
generator.generate_key(generate_salt, LENGTHS[:key])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def generate_password
|
|
29
|
+
SecureRandom.hex(LENGTHS[:password])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def generate_salt
|
|
33
|
+
SecureRandom.random_bytes(LENGTHS[:salt])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -1,45 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
%w[key_generator message_encryptor message_verifier].each do |filename|
|
|
4
|
-
require "active_support/#{filename}"
|
|
5
|
-
end
|
|
6
|
-
|
|
7
3
|
module Lite
|
|
8
4
|
module Encryption
|
|
9
5
|
class Message
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
Lite::Encryption.configuration.secret_key_base
|
|
13
|
-
).generate_key(
|
|
14
|
-
Lite::Encryption.configuration.secret_key_salt,
|
|
15
|
-
ActiveSupport::MessageEncryptor.key_len
|
|
16
|
-
).freeze
|
|
17
|
-
|
|
18
|
-
private_constant :KEY
|
|
19
|
-
|
|
20
|
-
class << self
|
|
21
|
-
|
|
22
|
-
%i[decrypt encrypt].each do |name|
|
|
23
|
-
define_method(name) do |value, opts = {}|
|
|
24
|
-
klass = new
|
|
25
|
-
klass.send(name, value, opts)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
7
|
+
extend Lite::Encryption::Helpers::ClassMethods
|
|
30
8
|
|
|
31
9
|
def decrypt(value, opts = {})
|
|
32
|
-
|
|
10
|
+
scheme = scheme_by_option(opts)
|
|
11
|
+
scheme.decrypt(value, **opts)
|
|
33
12
|
end
|
|
34
13
|
|
|
35
14
|
def encrypt(value, opts = {})
|
|
36
|
-
|
|
15
|
+
scheme = scheme_by_option(opts)
|
|
16
|
+
scheme.encrypt(value, **opts)
|
|
37
17
|
end
|
|
38
18
|
|
|
39
19
|
private
|
|
40
20
|
|
|
41
|
-
def
|
|
42
|
-
@
|
|
21
|
+
def deterministic_scheme
|
|
22
|
+
@deterministic_scheme ||= Lite::Encryption::Schemes::Deterministic.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def non_deterministic_scheme
|
|
26
|
+
@non_deterministic_scheme ||= Lite::Encryption::Schemes::NonDeterministic.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def scheme_by_option(options)
|
|
30
|
+
options.delete(:deterministic) ? deterministic_scheme : non_deterministic_scheme
|
|
43
31
|
end
|
|
44
32
|
|
|
45
33
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lite
|
|
4
|
+
module Encryption
|
|
5
|
+
module Schemes
|
|
6
|
+
class Deterministic
|
|
7
|
+
|
|
8
|
+
extend Lite::Encryption::Helpers::ClassMethods
|
|
9
|
+
|
|
10
|
+
def decrypt(value, _opts = {})
|
|
11
|
+
decoded_value = Base64.strict_decode64(value)
|
|
12
|
+
crypt(:decrypt, decoded_value)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def encrypt(value, _opts = {})
|
|
16
|
+
encoded_value = crypt(:encrypt, value)
|
|
17
|
+
Base64.strict_encode64(encoded_value)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def cipher
|
|
23
|
+
@cipher ||= Lite::Encryption::Key::CIPHER.dup
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def crypt(cipher_method, value)
|
|
27
|
+
cipher.send(cipher_method)
|
|
28
|
+
cipher.key = Lite::Encryption.configuration.encryption_salt
|
|
29
|
+
cipher.iv = Lite::Encryption.configuration.encryption_iv
|
|
30
|
+
cipher.update(value)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lite
|
|
4
|
+
module Encryption
|
|
5
|
+
module Schemes
|
|
6
|
+
class NonDeterministic
|
|
7
|
+
|
|
8
|
+
extend Lite::Encryption::Helpers::ClassMethods
|
|
9
|
+
|
|
10
|
+
def decrypt(value, opts = {})
|
|
11
|
+
cipher.decrypt_and_verify(value, **opts)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def encrypt(value, opts = {})
|
|
15
|
+
cipher.encrypt_and_sign(value, **opts)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def cipher
|
|
21
|
+
@cipher ||= ActiveSupport::MessageEncryptor.new(
|
|
22
|
+
Lite::Encryption.configuration.encryption_key,
|
|
23
|
+
cipher: Lite::Encryption::Key::CIPHER.name
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lite-encryption.gemspec
CHANGED
|
@@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.authors = ['Juan Gomez']
|
|
11
11
|
spec.email = %w[j.gomez@drexed.com]
|
|
12
12
|
|
|
13
|
-
# rubocop:disable
|
|
13
|
+
# rubocop:disable Layout/LineLength
|
|
14
14
|
spec.summary = 'ActiveSupport::MessageEncryptor encryption wrapper for PORO objects and ActiveModel attributes'
|
|
15
|
-
# rubocop:enable
|
|
15
|
+
# rubocop:enable Layout/LineLength
|
|
16
16
|
spec.homepage = 'http://drexed.github.io/lite-encryption'
|
|
17
17
|
spec.license = 'MIT'
|
|
18
18
|
|
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
)
|
|
28
28
|
else
|
|
29
29
|
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
|
30
|
-
|
|
30
|
+
'public gem pushes.'
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Specify which files should be added to the gem when it is released.
|
|
@@ -51,6 +51,7 @@ Gem::Specification.new do |spec|
|
|
|
51
51
|
spec.add_development_dependency 'rspec-rails'
|
|
52
52
|
spec.add_development_dependency 'rubocop'
|
|
53
53
|
spec.add_development_dependency 'rubocop-performance'
|
|
54
|
+
spec.add_development_dependency 'rubocop-rake'
|
|
54
55
|
spec.add_development_dependency 'rubocop-rspec'
|
|
55
56
|
spec.add_development_dependency 'sqlite3'
|
|
56
57
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lite-encryption
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juan Gomez
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -164,6 +164,20 @@ dependencies:
|
|
|
164
164
|
- - ">="
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
166
|
version: '0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: rubocop-rake
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
167
181
|
- !ruby/object:Gem::Dependency
|
|
168
182
|
name: rubocop-rspec
|
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -192,7 +206,7 @@ dependencies:
|
|
|
192
206
|
- - ">="
|
|
193
207
|
- !ruby/object:Gem::Version
|
|
194
208
|
version: '0'
|
|
195
|
-
description:
|
|
209
|
+
description:
|
|
196
210
|
email:
|
|
197
211
|
- j.gomez@drexed.com
|
|
198
212
|
executables: []
|
|
@@ -219,14 +233,18 @@ files:
|
|
|
219
233
|
- lib/lite/encryption.rb
|
|
220
234
|
- lib/lite/encryption/attribute.rb
|
|
221
235
|
- lib/lite/encryption/configuration.rb
|
|
236
|
+
- lib/lite/encryption/helpers/class_methods.rb
|
|
237
|
+
- lib/lite/encryption/key.rb
|
|
222
238
|
- lib/lite/encryption/message.rb
|
|
239
|
+
- lib/lite/encryption/schemes/deterministic.rb
|
|
240
|
+
- lib/lite/encryption/schemes/non_deterministic.rb
|
|
223
241
|
- lib/lite/encryption/version.rb
|
|
224
242
|
- lite-encryption.gemspec
|
|
225
243
|
homepage: http://drexed.github.io/lite-encryption
|
|
226
244
|
licenses:
|
|
227
245
|
- MIT
|
|
228
246
|
metadata: {}
|
|
229
|
-
post_install_message:
|
|
247
|
+
post_install_message:
|
|
230
248
|
rdoc_options: []
|
|
231
249
|
require_paths:
|
|
232
250
|
- lib
|
|
@@ -241,8 +259,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
241
259
|
- !ruby/object:Gem::Version
|
|
242
260
|
version: '0'
|
|
243
261
|
requirements: []
|
|
244
|
-
rubygems_version: 3.
|
|
245
|
-
signing_key:
|
|
262
|
+
rubygems_version: 3.2.24
|
|
263
|
+
signing_key:
|
|
246
264
|
specification_version: 4
|
|
247
265
|
summary: ActiveSupport::MessageEncryptor encryption wrapper for PORO objects and ActiveModel
|
|
248
266
|
attributes
|