cryptology 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -1
- data/.rspec +1 -0
- data/.rubocop.yml +5 -2
- data/.travis.yml +5 -5
- data/CHANGELOG.md +44 -15
- data/LICENSE.txt +1 -1
- data/README.md +92 -33
- data/bin/console +1 -1
- data/bin/setup +2 -1
- data/cryptology.gemspec +9 -7
- data/lib/cryptology.rb +1 -1
- data/lib/cryptology/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b70731c946f0048683b1eb2c24042b230fc217eed02189b7a367bbf7c9b06409
|
4
|
+
data.tar.gz: 9bded19f40166bf83f01d4e2a00b9c787887f8766500ac3707bbc0935fc65ce6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a546c32bf248501d522f938c360d87bce367469f988fcf832b9f096be5f9241e944564c295e4de0be5b3b80f654ce03470a9d60f28159dee4af1bc9bb45fc0b
|
7
|
+
data.tar.gz: cb41d1d05ed2a03705f3ecad3cd3f28d4397b9c2dda90e2c2d1e388b2c0b178f86792ad66d7e10e23d19339ed1222f614c83d82685fc75c924c1f2cb1f36abe7
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -2,7 +2,7 @@ AllCops:
|
|
2
2
|
TargetRubyVersion: 2.4
|
3
3
|
|
4
4
|
Metrics/BlockLength:
|
5
|
-
ExcludedMethods: RSpec.describe, context
|
5
|
+
ExcludedMethods: [RSpec.describe, context]
|
6
6
|
|
7
7
|
Metrics/LineLength:
|
8
8
|
Max: 100
|
@@ -10,8 +10,11 @@ Metrics/LineLength:
|
|
10
10
|
Metrics/ParameterLists:
|
11
11
|
Max: 6
|
12
12
|
|
13
|
+
Naming/MethodParameterName:
|
14
|
+
MinNameLength: 2
|
15
|
+
|
13
16
|
Style/Documentation:
|
14
17
|
Enabled: false
|
15
18
|
|
16
19
|
Style/FrozenStringLiteralComment:
|
17
|
-
|
20
|
+
EnforcedStyle: never
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,53 @@
|
|
1
|
-
|
1
|
+
# [2.1.0](https://github.com/rubysamurai/cryptology/compare/v2.0.0...v2.1.0) (2020-03-04)
|
2
2
|
|
3
|
-
- New: `encrypt` method returns a hash
|
4
|
-
- Improvement: `key` hashing method updated
|
5
|
-
- Improvement: `iv` is always set if algorithm supports it
|
6
|
-
- Improvement: Optional `salt` and `iter` arguments
|
7
|
-
- Ruby versioning: Support for Ruby 2.4
|
8
3
|
|
9
|
-
|
4
|
+
### Features
|
10
5
|
|
11
|
-
|
6
|
+
* Require Ruby 2.4 ([796d1a1](https://github.com/rubysamurai/cryptology/commit/796d1a1ae6e7bcbc2a0062108f8aec0ed68a6d58))
|
12
7
|
|
13
|
-
## 1.1.0 (2015-12-08)
|
14
8
|
|
15
|
-
- Improvement: Switch to keyword arguments
|
16
|
-
- Ruby versioning: Drop support for Ruby 2.0
|
17
9
|
|
18
|
-
|
10
|
+
# [2.0.0](https://github.com/rubysamurai/cryptology/compare/v1.2.0...v2.0.0) (2017-06-27)
|
19
11
|
|
20
|
-
- Bug fix: Allow iv to be nil
|
21
12
|
|
22
|
-
|
13
|
+
### Features
|
23
14
|
|
24
|
-
|
15
|
+
* `encrypt` method returns a hash ([a392972](https://github.com/rubysamurai/cryptology/commit/a3929722c089c6871de9afb91d3199f35a883997))
|
16
|
+
* Always set `iv` when possible ([a392972](https://github.com/rubysamurai/cryptology/commit/a3929722c089c6871de9afb91d3199f35a883997))
|
17
|
+
* Digest `key` with PBKDF2 SHA256 with an optional `salt` argument ([2296d04](https://github.com/rubysamurai/cryptology/commit/2296d04cd4834d09d0cb1be8b40688b7ce25fa36))
|
18
|
+
* Optional `iter` argument ([a3a774d](https://github.com/rubysamurai/cryptology/commit/a3a774d87befa373d45274b350687017a8861abe))
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
# [1.2.0](https://github.com/rubysamurai/cryptology/compare/v1.1.0...v1.2.0) (2015-12-10)
|
23
|
+
|
24
|
+
|
25
|
+
### Features
|
26
|
+
|
27
|
+
* `decryptable?` method ([610dfce](https://github.com/rubysamurai/cryptology/commit/610dfce5f24238327dac85bbf0bca41ad8309dbf))
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# [1.1.0](https://github.com/rubysamurai/cryptology/compare/v1.0.1...v1.1.0) (2015-12-08)
|
32
|
+
|
33
|
+
|
34
|
+
### Features
|
35
|
+
|
36
|
+
* Require Ruby 2.1 ([bce1367](https://github.com/rubysamurai/cryptology/commit/bce1367c51a40239de39c0c7464c6666356a75c1))
|
37
|
+
* Use keyword arguments ([31de476](https://github.com/rubysamurai/cryptology/commit/31de476d3057101efef95fb3378b27fdf9ad9e32))
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
# [1.0.1](https://github.com/rubysamurai/cryptology/compare/v1.0.0...v1.0.1) (2015-12-08)
|
42
|
+
|
43
|
+
|
44
|
+
### Bug Fixes
|
45
|
+
|
46
|
+
* Allow `iv` to be nil ([5abf3e1](https://github.com/rubysamurai/cryptology/commit/5abf3e1f5f40eebd0b38be6b2b57fac642c83cb4))
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
# 1.0.0 (2015-12-07)
|
51
|
+
|
52
|
+
|
53
|
+
Initial release.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Cryptology
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/cryptology.svg)](https://badge.fury.io/rb/cryptology)
|
4
|
-
[![Build Status](https://travis-ci.
|
4
|
+
[![Build Status](https://travis-ci.com/rubysamurai/cryptology.svg?branch=master)](https://travis-ci.com/rubysamurai/cryptology)
|
5
5
|
|
6
|
-
`Cryptology` is a wrapper for encryption and decryption in Ruby
|
6
|
+
`Cryptology` is a wrapper for encryption and decryption in Ruby using OpenSSL. By default `AES-256-CBC` cipher is used.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -25,65 +25,124 @@ $ gem install cryptology
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
# Encrypting
|
28
|
-
Cryptology.encrypt(data: data, key: key, cipher: cipher, iv: iv)
|
28
|
+
Cryptology.encrypt(data: data, key: key, salt: salt, iter: iter, cipher: cipher, iv: iv)
|
29
29
|
|
30
30
|
# Decrypting
|
31
|
-
Cryptology.decrypt(data: data, key: key, cipher: cipher, iv: iv)
|
31
|
+
Cryptology.decrypt(data: data, key: key, salt: salt, iter: iter, cipher: cipher, iv: iv)
|
32
32
|
|
33
33
|
# Check decryption ability (true if can be decrypted, false otherwise)
|
34
|
-
Cryptology.decryptable?(data: data, key: key, cipher: cipher, iv: iv)
|
34
|
+
Cryptology.decryptable?(data: data, key: key, salt: salt, iter: iter, cipher: cipher, iv: iv)
|
35
35
|
```
|
36
36
|
|
37
37
|
|
38
|
-
Argument | Required? | Default
|
39
|
-
|
40
|
-
data | **Yes** | n/a
|
41
|
-
key | **Yes** | n/a
|
42
|
-
|
43
|
-
|
38
|
+
Argument | Required? | Default | Comment
|
39
|
+
---------|-----------|-------------------------|-------------
|
40
|
+
data | **Yes** | n/a | Data to encrypt or decrypt
|
41
|
+
key | **Yes** | n/a | Secure key for encryption and decryption
|
42
|
+
salt | *No* | Random 16 bytes | Value to prevent attacks on key based on dictionaries
|
43
|
+
iter | *No* | 10,000 | Number of iterations to adjust computation time
|
44
|
+
cipher | *No* | `AES-256-CBC` | Cipher algorithm
|
45
|
+
iv | *No* | Random iv for algorithm | Initialization vector
|
44
46
|
|
45
47
|
Example:
|
46
48
|
|
47
49
|
```ruby
|
48
50
|
# Data to encrypt (required)
|
49
51
|
data = 'Very, very confidential data'
|
52
|
+
|
50
53
|
# Secure key for encryption (required)
|
51
|
-
key = '
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
key = 'password_01X'
|
55
|
+
|
56
|
+
# Salt (optional)
|
57
|
+
salt = OpenSSL::Random.random_bytes(16)
|
58
|
+
# => "r\x97\xEA9]I\x18\x05\xEAZ\xA2\xBB^Y=\x83"
|
59
|
+
|
60
|
+
# Number of iterations (optional)
|
61
|
+
iter = 50000
|
62
|
+
|
63
|
+
# Use Camellia cipher in CBC mode (optional)
|
64
|
+
cipher = 'CAMELLIA-256-CBC'
|
65
|
+
|
66
|
+
# Initialization vector for CAMELLIA-256-CBC (optional)
|
67
|
+
iv = OpenSSL::Cipher.new(cipher).random_iv
|
68
|
+
# => "\xB0\xCA\xBBc5'\x03i\x01\xC1@\xC0\xB6\xCE7+"
|
56
69
|
|
57
70
|
# Encrypt our data
|
58
|
-
|
71
|
+
enc = Cryptology.encrypt(data: data,
|
72
|
+
key: key,
|
73
|
+
salt: salt,
|
74
|
+
iter: iter,
|
75
|
+
cipher: cipher,
|
76
|
+
iv: iv)
|
77
|
+
|
78
|
+
# => { "cipher"=>"CAMELLIA-256-CBC",
|
79
|
+
# "salt"=>"r\x97\xEA9]I\x18\x05\xEAZ\xA2\xBB^Y=\x83",
|
80
|
+
# "iter"=>50000,
|
81
|
+
# "iv"=>"\xB0\xCA\xBBc5'\x03i\x01\xC1@\xC0\xB6\xCE7+",
|
82
|
+
# "data"=>"k+e3JZpkFIgkB15LjK85k5roojNgawN9yPEp6CXGhCQ=\n" }
|
59
83
|
|
60
84
|
# Verify that data can be decrypted
|
61
|
-
Cryptology.decryptable?(data:
|
85
|
+
Cryptology.decryptable?(data: enc['data'],
|
86
|
+
key: key,
|
87
|
+
salt: enc['salt'],
|
88
|
+
iter: enc['iter'],
|
89
|
+
cipher: enc['cipher'],
|
90
|
+
iv: enc['iv'])
|
62
91
|
# => true
|
63
92
|
|
64
93
|
# Decrypt our data
|
65
|
-
plain = Cryptology.decrypt(data:
|
94
|
+
plain = Cryptology.decrypt(data: enc['data'],
|
95
|
+
key: key,
|
96
|
+
salt: enc['salt'],
|
97
|
+
iter: enc['iter'],
|
98
|
+
cipher: enc['cipher'],
|
99
|
+
iv: enc['iv'])
|
100
|
+
# => "Very, very confidential data"
|
66
101
|
```
|
67
102
|
|
68
103
|
### Cipher algorithms
|
69
104
|
|
70
|
-
|
71
|
-
|
72
|
-
```
|
73
|
-
$ openssl list-cipher-algorithms
|
74
|
-
```
|
105
|
+
> **Note:** Ruby 2.4 and above would throw an error if key is too short or too long for a given cipher algorithm (see [this commit](https://github.com/ruby/ruby/commit/ce635262f53b760284d56bb1027baebaaec175d1) for details) Make sure you choose a cipher with 32 bytes size key.
|
75
106
|
|
76
|
-
|
107
|
+
List of tested and supported ciphers:
|
77
108
|
|
78
|
-
```ruby
|
79
|
-
require 'openssl'
|
80
|
-
puts OpenSSL::Cipher.ciphers
|
81
109
|
```
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
110
|
+
Ruby 2.7.0, OpenSSL 1.1.1
|
111
|
+
|
112
|
+
AES-128-XTS
|
113
|
+
AES-256-CBC
|
114
|
+
AES-256-CBC-HMAC-SHA1
|
115
|
+
AES-256-CBC-HMAC-SHA256
|
116
|
+
AES-256-CFB
|
117
|
+
AES-256-CFB1
|
118
|
+
AES-256-CFB8
|
119
|
+
AES-256-CTR
|
120
|
+
AES-256-ECB
|
121
|
+
AES-256-OFB
|
122
|
+
AES256
|
123
|
+
|
124
|
+
ARIA-256-CBC
|
125
|
+
ARIA-256-CFB
|
126
|
+
ARIA-256-CFB1
|
127
|
+
ARIA-256-CFB8
|
128
|
+
ARIA-256-CTR
|
129
|
+
ARIA-256-ECB
|
130
|
+
ARIA-256-OFB
|
131
|
+
ARIA256
|
132
|
+
|
133
|
+
CAMELLIA-256-CBC
|
134
|
+
CAMELLIA-256-CFB
|
135
|
+
CAMELLIA-256-CFB1
|
136
|
+
CAMELLIA-256-CFB8
|
137
|
+
CAMELLIA-256-CTR
|
138
|
+
CAMELLIA-256-ECB
|
139
|
+
CAMELLIA-256-OFB
|
140
|
+
CAMELLIA256
|
141
|
+
|
142
|
+
CHACHA20
|
143
|
+
CHACHA20-POLY1305
|
144
|
+
```
|
86
145
|
|
87
146
|
## License
|
88
147
|
|
89
|
-
`Cryptology` © Dmitriy Tarasov
|
148
|
+
`Cryptology` © Dmitriy Tarasov. Released under the [MIT](LICENSE.txt) license.
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/cryptology.gemspec
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'cryptology/version'
|
1
|
+
require_relative 'lib/cryptology/version'
|
6
2
|
|
7
3
|
Gem::Specification.new do |spec|
|
8
4
|
spec.name = 'cryptology'
|
@@ -15,12 +11,18 @@ Gem::Specification.new do |spec|
|
|
15
11
|
spec.homepage = 'https://github.com/rubysamurai/cryptology'
|
16
12
|
spec.license = 'MIT'
|
17
13
|
|
18
|
-
spec.
|
14
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/rubysamurai/cryptology/issues'
|
15
|
+
spec.metadata['changelog_uri'] = 'https://github.com/rubysamurai/cryptology/blob/master/CHANGELOG.md'
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
|
19
21
|
spec.bindir = 'exe'
|
20
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
23
|
spec.require_paths = ['lib']
|
22
24
|
|
23
|
-
spec.required_ruby_version = '>= 2.
|
25
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
24
26
|
|
25
27
|
spec.add_development_dependency 'rake', '>= 12.0'
|
26
28
|
spec.add_development_dependency 'rspec', '>= 3.6'
|
data/lib/cryptology.rb
CHANGED
@@ -23,7 +23,7 @@ module Cryptology
|
|
23
23
|
def self.decryptable?(data:, key:, salt:, iter: 10_000, cipher: 'AES-256-CBC', iv:)
|
24
24
|
return true if decrypt(data: data, key: key, salt: salt, iter: iter, cipher: cipher, iv: iv)
|
25
25
|
rescue OpenSSL::Cipher::CipherError
|
26
|
-
|
26
|
+
false
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.encrypt_data(data, key, cipher, iv)
|
data/lib/cryptology/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptology
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Tarasov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -62,7 +62,9 @@ files:
|
|
62
62
|
homepage: https://github.com/rubysamurai/cryptology
|
63
63
|
licenses:
|
64
64
|
- MIT
|
65
|
-
metadata:
|
65
|
+
metadata:
|
66
|
+
bug_tracker_uri: https://github.com/rubysamurai/cryptology/issues
|
67
|
+
changelog_uri: https://github.com/rubysamurai/cryptology/blob/master/CHANGELOG.md
|
66
68
|
post_install_message:
|
67
69
|
rdoc_options: []
|
68
70
|
require_paths:
|
@@ -71,15 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
73
|
requirements:
|
72
74
|
- - ">="
|
73
75
|
- !ruby/object:Gem::Version
|
74
|
-
version: 2.
|
76
|
+
version: 2.4.0
|
75
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
78
|
requirements:
|
77
79
|
- - ">="
|
78
80
|
- !ruby/object:Gem::Version
|
79
81
|
version: '0'
|
80
82
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.6.12
|
83
|
+
rubygems_version: 3.0.6
|
83
84
|
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: Symmetric encryption and decryption with OpenSSL
|