cryptology 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -0
- data/.travis.yml +5 -5
- data/CHANGELOG.md +12 -4
- data/Rakefile +3 -1
- data/cryptology.gemspec +6 -5
- data/lib/cryptology.rb +33 -25
- data/lib/cryptology/version.rb +1 -1
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b487542337e1013f886ac420c0e2a53b0ec22e3
|
4
|
+
data.tar.gz: 9c1e6d5ace17fa5fbedcfd6c6d870e27e7f076f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eac2db8af311b962af96c6e83f02591e181b65dd147268cf7272b4040557c8e8b9a0cc85b3851fe0c923f8bda14e7f4e140554f620a7f52fda140bf402355611
|
7
|
+
data.tar.gz: 0c39c3408209210ff0f05337ae94196a638a3fdd831d83e2ada51262a6d2d5887016ac6beff5c22a62c27938b61f0397b6b73c70c80a389f97e07b6e925dd2d6
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
|
4
|
+
Metrics/BlockLength:
|
5
|
+
ExcludedMethods: RSpec.describe, context
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Max: 100
|
9
|
+
|
10
|
+
Metrics/ParameterLists:
|
11
|
+
Max: 6
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/FrozenStringLiteralComment:
|
17
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,24 @@
|
|
1
|
+
## 2.0.0 (2017-06-27)
|
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
|
+
|
1
9
|
## 1.2.0 (2015-12-10)
|
2
10
|
|
3
|
-
- Improvement: Add decryptable
|
11
|
+
- Improvement: Add `decryptable?` helper method
|
4
12
|
|
5
13
|
## 1.1.0 (2015-12-08)
|
6
14
|
|
7
15
|
- Improvement: Switch to keyword arguments
|
8
|
-
- Ruby
|
16
|
+
- Ruby versioning: Drop support for Ruby 2.0
|
9
17
|
|
10
18
|
## 1.0.1 (2015-12-08)
|
11
19
|
|
12
|
-
- Bug
|
20
|
+
- Bug fix: Allow iv to be nil
|
13
21
|
|
14
22
|
## 1.0.0 (2015-12-07)
|
15
23
|
|
16
|
-
- Initial release
|
24
|
+
- Initial release
|
data/Rakefile
CHANGED
data/cryptology.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'cryptology/version'
|
@@ -9,18 +10,18 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Dmitriy Tarasov']
|
10
11
|
spec.email = ['info@rubysamurai.com']
|
11
12
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
13
|
+
spec.summary = 'Symmetric encryption and decryption with OpenSSL'
|
14
|
+
spec.description = 'Symmetric encryption and decryption with OpenSSL'
|
14
15
|
spec.homepage = 'https://github.com/rubysamurai/cryptology'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
|
18
19
|
spec.bindir = 'exe'
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
21
|
spec.require_paths = ['lib']
|
21
22
|
|
22
23
|
spec.required_ruby_version = '>= 2.1.0'
|
23
24
|
|
24
|
-
spec.add_development_dependency 'rake', '
|
25
|
-
spec.add_development_dependency 'rspec', '
|
25
|
+
spec.add_development_dependency 'rake', '>= 12.0'
|
26
|
+
spec.add_development_dependency 'rspec', '>= 3.6'
|
26
27
|
end
|
data/lib/cryptology.rb
CHANGED
@@ -3,42 +3,50 @@ require 'openssl'
|
|
3
3
|
require 'base64'
|
4
4
|
|
5
5
|
module Cryptology
|
6
|
-
def self.encrypt(data:, key:, cipher: 'AES-256-CBC', iv: nil)
|
7
|
-
|
8
|
-
::
|
6
|
+
def self.encrypt(data:, key:, salt: nil, iter: 10_000, cipher: 'AES-256-CBC', iv: nil)
|
7
|
+
salt ||= OpenSSL::Random.random_bytes(16)
|
8
|
+
iv ||= OpenSSL::Cipher.new(cipher).random_iv
|
9
|
+
encrypted = encrypt_data(data.to_s, digest_key(key, salt, iter), cipher, iv)
|
10
|
+
{ 'cipher' => cipher,
|
11
|
+
'salt' => salt,
|
12
|
+
'iter' => iter,
|
13
|
+
'iv' => iv,
|
14
|
+
'data' => ::Base64.encode64(encrypted) }
|
9
15
|
end
|
10
16
|
|
11
|
-
def self.decrypt(data:, key:, cipher: 'AES-256-CBC', iv:
|
17
|
+
def self.decrypt(data:, key:, salt:, iter: 10_000, cipher: 'AES-256-CBC', iv:)
|
12
18
|
base64_decoded = ::Base64.decode64(data.to_s)
|
13
|
-
decrypt_data(base64_decoded,
|
19
|
+
decrypt_data(base64_decoded, digest_key(key, salt, iter), cipher, iv)
|
14
20
|
.force_encoding('UTF-8').encode
|
15
21
|
end
|
16
22
|
|
17
|
-
def self.decryptable?(data:, key:, cipher: 'AES-256-CBC', iv:
|
18
|
-
return true if decrypt(data: data, key: key, cipher: cipher, iv: iv)
|
23
|
+
def self.decryptable?(data:, key:, salt:, iter: 10_000, cipher: 'AES-256-CBC', iv:)
|
24
|
+
return true if decrypt(data: data, key: key, salt: salt, iter: iter, cipher: cipher, iv: iv)
|
19
25
|
rescue OpenSSL::Cipher::CipherError
|
20
26
|
return false
|
21
27
|
end
|
22
28
|
|
23
|
-
|
29
|
+
def self.encrypt_data(data, key, cipher, iv)
|
30
|
+
c = OpenSSL::Cipher.new(cipher)
|
31
|
+
c.encrypt
|
32
|
+
c.key = key
|
33
|
+
c.iv = iv unless iv.length != c.random_iv.length
|
34
|
+
c.update(data) + c.final
|
35
|
+
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
def self.decrypt_data(data, key, cipher, iv)
|
38
|
+
decipher = OpenSSL::Cipher.new(cipher)
|
39
|
+
decipher.decrypt
|
40
|
+
decipher.key = key
|
41
|
+
decipher.iv = iv unless iv.length != decipher.random_iv.length
|
42
|
+
decipher.update(data) + decipher.final
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
decipher.update(data) + decipher.final
|
39
|
-
end
|
45
|
+
def self.digest_key(key, salt, iter)
|
46
|
+
digest = OpenSSL::Digest::SHA256.new
|
47
|
+
len = digest.digest_length
|
48
|
+
OpenSSL::PKCS5.pbkdf2_hmac(key, salt, iter, len, digest)
|
49
|
+
end
|
40
50
|
|
41
|
-
|
42
|
-
::OpenSSL::Digest::SHA256.digest(key)
|
43
|
-
end
|
51
|
+
private_class_method :encrypt_data, :decrypt_data, :digest_key
|
44
52
|
end
|
data/lib/cryptology/version.rb
CHANGED
metadata
CHANGED
@@ -1,45 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptology
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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: 2017-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '12.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '12.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
41
|
-
description:
|
42
|
-
by OpenSSL
|
40
|
+
version: '3.6'
|
41
|
+
description: Symmetric encryption and decryption with OpenSSL
|
43
42
|
email:
|
44
43
|
- info@rubysamurai.com
|
45
44
|
executables: []
|
@@ -48,6 +47,7 @@ extra_rdoc_files: []
|
|
48
47
|
files:
|
49
48
|
- ".gitignore"
|
50
49
|
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
51
|
- ".travis.yml"
|
52
52
|
- CHANGELOG.md
|
53
53
|
- Gemfile
|
@@ -79,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.6.12
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
|
-
summary:
|
86
|
-
by OpenSSL
|
85
|
+
summary: Symmetric encryption and decryption with OpenSSL
|
87
86
|
test_files: []
|