porky_lib 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +1 -1
- data/Gemfile.lock +4 -4
- data/lib/porky_lib/symmetric.rb +47 -0
- data/lib/porky_lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 073de134fa0c5a3b836f975475ecd1373488cc7a1549f1d5d363a3f1363c6488
|
4
|
+
data.tar.gz: 0e03c14d1d9251f9ce5caa4b47d172c9c09991040aebc7a36e28513edddeccac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 774a7f3448d8dacc59dbd8302b9edbe70a5e6b28ee6d7bb95edd9e7b3e3a1b050a125ed7c31027358849adb3a9bf7fdf592ba19f78e1bb6a76eb9bbe978dfdc1
|
7
|
+
data.tar.gz: f7f67d35b7ad9624addee071af67b94c9def18aff469f62636ee92b781342cd98caedd44ac4ad3a7216fb5b95d2adaee6dbd6a7bfa5242f7d47e41cd76ad043c
|
data/.hound.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
porky_lib (0.6.
|
4
|
+
porky_lib (0.6.2)
|
5
5
|
aws-sdk-kms
|
6
6
|
aws-sdk-s3
|
7
7
|
msgpack
|
@@ -13,8 +13,8 @@ GEM
|
|
13
13
|
specs:
|
14
14
|
ast (2.4.0)
|
15
15
|
aws-eventstream (1.0.3)
|
16
|
-
aws-partitions (1.
|
17
|
-
aws-sdk-core (3.
|
16
|
+
aws-partitions (1.207.0)
|
17
|
+
aws-sdk-core (3.65.1)
|
18
18
|
aws-eventstream (~> 1.0, >= 1.0.2)
|
19
19
|
aws-partitions (~> 1.0)
|
20
20
|
aws-sigv4 (~> 1.1)
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
aws-sdk-kms (1.24.0)
|
23
23
|
aws-sdk-core (~> 3, >= 3.61.1)
|
24
24
|
aws-sigv4 (~> 1.1)
|
25
|
-
aws-sdk-s3 (1.
|
25
|
+
aws-sdk-s3 (1.47.0)
|
26
26
|
aws-sdk-core (~> 3, >= 3.61.1)
|
27
27
|
aws-sdk-kms (~> 1)
|
28
28
|
aws-sigv4 (~> 1.1)
|
data/lib/porky_lib/symmetric.rb
CHANGED
@@ -191,6 +191,53 @@ class PorkyLib::Symmetric
|
|
191
191
|
"\0" * length
|
192
192
|
end
|
193
193
|
|
194
|
+
def encrypt_with_key_with_benchmark(plaintext, plaintext_key)
|
195
|
+
encryption_statistics = {}
|
196
|
+
|
197
|
+
nonce, ciphertext = benchmark_block(encryption_statistics, :encrypt) do
|
198
|
+
# Initialize the box
|
199
|
+
secret_box = RbNaCl::SecretBox.new(plaintext_key)
|
200
|
+
|
201
|
+
# First, make a nonce: A single-use value never repeated under the same key
|
202
|
+
# The nonce isn't secret, and can be sent with the ciphertext.
|
203
|
+
# The cipher instance has a nonce_bytes method for determining how many bytes should be in a nonce
|
204
|
+
nonce = RbNaCl::Random.random_bytes(secret_box.nonce_bytes)
|
205
|
+
|
206
|
+
# Encrypt a message with SecretBox
|
207
|
+
ciphertext = secret_box.encrypt(nonce, plaintext)
|
208
|
+
|
209
|
+
[nonce, ciphertext]
|
210
|
+
end
|
211
|
+
|
212
|
+
result = OpenStruct.new
|
213
|
+
|
214
|
+
result.ciphertext = ciphertext
|
215
|
+
result.nonce = nonce
|
216
|
+
result.statistics = encryption_statistics
|
217
|
+
|
218
|
+
result
|
219
|
+
end
|
220
|
+
|
221
|
+
def decrypt_with_key_with_benchmark(ciphertext, plaintext_key, nonce)
|
222
|
+
encryption_statistics = {}
|
223
|
+
|
224
|
+
plaintext = benchmark_block(encryption_statistics, :decrypt) do
|
225
|
+
secret_box = RbNaCl::SecretBox.new(plaintext_key)
|
226
|
+
|
227
|
+
# Decrypt the message
|
228
|
+
plaintext = secret_box.decrypt(nonce, ciphertext)
|
229
|
+
|
230
|
+
plaintext
|
231
|
+
end
|
232
|
+
|
233
|
+
result = OpenStruct.new
|
234
|
+
|
235
|
+
result.plaintext = plaintext
|
236
|
+
result.statistics = encryption_statistics
|
237
|
+
|
238
|
+
result
|
239
|
+
end
|
240
|
+
|
194
241
|
private
|
195
242
|
|
196
243
|
def benchmark_block(statistics, stat_label)
|
data/lib/porky_lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: porky_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Fletcher
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-kms
|