easy-crypto 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +14 -2
- data/lib/easycrypto/crypto.rb +7 -1
- data/lib/easycrypto/version.rb +1 -1
- data/spec/easycrypto/crypto_spec.rb +16 -0
- 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: f4ad3e00c48d1045ceb274232305aff4a182022395bbe2b610e2b348cf10e18b
|
4
|
+
data.tar.gz: 00adb629016b33ba4a3f905488abdbf9de0f44b4cf53a43b4d76d18d7f9d8e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b7d604a6a3f4b50f3c4f15d687e2c3833e5116e85b4989b1c91ee0f527e8a897596078c7fb84e77c464f68f3cfbd8a44be698a399bb7a234618c361a34aae71
|
7
|
+
data.tar.gz: 96da1fe387f964f5a1d7a15ea3ef8ae1e81f2544a9a2a9a3c50922473c8acf23fb163bccad7e4670ecbb41b7e6181cdfcdbd2d587c580dcf991f39903c6987ca
|
data/Gemfile.lock
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# EasyCrypto
|
1
|
+
# EasyCrypto [![Build Status](https://travis-ci.org/emartech/ruby-easy-crypto.svg?branch=master)](https://travis-ci.org/emartech/ruby-easy-crypto) [![Gem Version](https://badge.fury.io/rb/easy-crypto.svg)](https://badge.fury.io/rb/easy-crypto)
|
2
2
|
|
3
3
|
Provides simple wrappers around the openssl crypto implementation.
|
4
4
|
|
@@ -20,7 +20,19 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
### Encrypt with previously derived key
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'easycrypto'
|
27
|
+
|
28
|
+
key_password = 'secret password'
|
29
|
+
plain_text = 'data to encrypt ...'
|
30
|
+
|
31
|
+
ecrypto = EasyCrypto::Crypto.new
|
32
|
+
|
33
|
+
key = EasyCrypto::Key.generate(key_password)
|
34
|
+
ecrypto.encrypt_with_key(key, plain_text)
|
35
|
+
```
|
24
36
|
|
25
37
|
## License
|
26
38
|
|
data/lib/easycrypto/crypto.rb
CHANGED
@@ -10,6 +10,7 @@ module EasyCrypto
|
|
10
10
|
|
11
11
|
def encrypt_with_key(key, plaintext)
|
12
12
|
validate_key_type(key)
|
13
|
+
validate_plaintext(plaintext)
|
13
14
|
|
14
15
|
iv = OpenSSL::Random.random_bytes(Crypto::IV_LEN)
|
15
16
|
cipher = create_cipher(key, iv)
|
@@ -22,7 +23,12 @@ module EasyCrypto
|
|
22
23
|
private
|
23
24
|
|
24
25
|
def validate_key_type(key)
|
25
|
-
raise TypeError 'key must have Key type' unless key.is_a?(EasyCrypto::Key)
|
26
|
+
raise TypeError, 'key must have Key type' unless key.is_a?(EasyCrypto::Key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_plaintext(plaintext)
|
30
|
+
raise TypeError, 'Encryptable data must be a string' unless plaintext.is_a?(String)
|
31
|
+
raise ArgumentError, 'Encryptable data must not be empty' if plaintext.empty?
|
26
32
|
end
|
27
33
|
|
28
34
|
def create_cipher(key, iv)
|
data/lib/easycrypto/version.rb
CHANGED
@@ -12,5 +12,21 @@ RSpec.describe EasyCrypto::Crypto do
|
|
12
12
|
encrypted = ecrypto.encrypt_with_key(key, 'plain text')
|
13
13
|
expect(encrypted).not_to include("\n")
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'raise error if the encryptable data is not a string' do
|
17
|
+
ecrypto = EasyCrypto::Crypto.new
|
18
|
+
key = EasyCrypto::Key.generate('key password', 12)
|
19
|
+
expect{
|
20
|
+
ecrypto.encrypt_with_key(key, 1234)
|
21
|
+
}.to raise_error(TypeError, 'Encryptable data must be a string')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raise error if the encryptable data is empty' do
|
25
|
+
ecrypto = EasyCrypto::Crypto.new
|
26
|
+
key = EasyCrypto::Key.generate('key password', 12)
|
27
|
+
expect{
|
28
|
+
ecrypto.encrypt_with_key(key, '')
|
29
|
+
}.to raise_error(ArgumentError, 'Encryptable data must not be empty')
|
30
|
+
end
|
15
31
|
end
|
16
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-crypto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emarsys Security
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|