cryptology 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3b487542337e1013f886ac420c0e2a53b0ec22e3
4
- data.tar.gz: 9c1e6d5ace17fa5fbedcfd6c6d870e27e7f076f0
2
+ SHA256:
3
+ metadata.gz: b70731c946f0048683b1eb2c24042b230fc217eed02189b7a367bbf7c9b06409
4
+ data.tar.gz: 9bded19f40166bf83f01d4e2a00b9c787887f8766500ac3707bbc0935fc65ce6
5
5
  SHA512:
6
- metadata.gz: eac2db8af311b962af96c6e83f02591e181b65dd147268cf7272b4040557c8e8b9a0cc85b3851fe0c923f8bda14e7f4e140554f620a7f52fda140bf402355611
7
- data.tar.gz: 0c39c3408209210ff0f05337ae94196a638a3fdd831d83e2ada51262a6d2d5887016ac6beff5c22a62c27938b61f0397b6b73c70c80a389f97e07b6e925dd2d6
6
+ metadata.gz: 8a546c32bf248501d522f938c360d87bce367469f988fcf832b9f096be5f9241e944564c295e4de0be5b3b80f654ce03470a9d60f28159dee4af1bc9bb45fc0b
7
+ data.tar.gz: cb41d1d05ed2a03705f3ecad3cd3f28d4397b9c2dda90e2c2d1e388b2c0b178f86792ad66d7e10e23d19339ed1222f614c83d82685fc75c924c1f2cb1f36abe7
data/.gitignore CHANGED
@@ -1,9 +1,12 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
6
+ /Gemfile.lock
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
@@ -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
- Enabled: false
20
+ EnforcedStyle: never
@@ -1,7 +1,7 @@
1
- sudo: false
1
+ dist: bionic
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.10
5
- - 2.2.7
6
- - 2.3.4
7
- - 2.4.1
4
+ - 2.4.9
5
+ - 2.5.7
6
+ - 2.6.5
7
+ - 2.7.0
@@ -1,24 +1,53 @@
1
- ## 2.0.0 (2017-06-27)
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
- ## 1.2.0 (2015-12-10)
4
+ ### Features
10
5
 
11
- - Improvement: Add `decryptable?` helper method
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
- ## 1.0.1 (2015-12-08)
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
- ## 1.0.0 (2015-12-07)
13
+ ### Features
23
14
 
24
- - Initial release
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.
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Dmitriy Tarasov
3
+ Copyright (c) 2017 Dmitriy Tarasov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.org/rubysamurai/cryptology.svg?branch=master)](https://travis-ci.org/rubysamurai/cryptology)
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. Supports all cipher algorithms, that are available in installed version of OpenSSL. By default `AES-256-CBC` is used.
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 | Comment
39
- ---------|-----------|---------------|-------------
40
- data | **Yes** | n/a | Data to encrypt or decrypt
41
- key | **Yes** | n/a | Secure key for encryption and decryption
42
- cipher | *No* | `AES-256-CBC` | Cipher algorithm
43
- iv | *No* | `nil` | Initialization vector for CBC, CFB, CTR, OFB modes
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 = 'veryLongAndSecurePassword_6154309'
52
- # Use Blowfish cipher in CBC mode (optional)
53
- cipher = 'BF-CBC'
54
- # Initialization vector for BF-CBC (optional)
55
- iv = OpenSSL::Cipher::Cipher.new(cipher).random_iv
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
- encrypted = Cryptology.encrypt(data: data, key: key, cipher: cipher, iv: iv)
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: encrypted, key: key, cipher: cipher, iv: iv)
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: encrypted, key: key, cipher: cipher, iv: iv)
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
- To get a list of available cipher algorithms in your environment run this command:
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
- or this Ruby code:
107
+ List of tested and supported ciphers:
77
108
 
78
- ```ruby
79
- require 'openssl'
80
- puts OpenSSL::Cipher.ciphers
81
109
  ```
82
-
83
- ## Contributing
84
-
85
- Anyone is welcome to contribute to Cryptology. Please [raise an issue](https://github.com/rubysamurai/cryptology/issues), fork the project, make changes to your forked repository and submit a pull request.
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, 2015. Released under the [MIT](https://github.com/rubysamurai/cryptology/blob/master/LICENSE.txt) license.
148
+ `Cryptology` © Dmitriy Tarasov. Released under the [MIT](LICENSE.txt) license.
@@ -11,4 +11,4 @@ require 'cryptology'
11
11
  # Pry.start
12
12
 
13
13
  require 'irb'
14
- IRB.start
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,6 +1,7 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
+ set -vx
4
5
 
5
6
  bundle install
6
7
 
@@ -1,8 +1,4 @@
1
- # coding: utf-8
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.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
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.1.0'
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'
@@ -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
- return false
26
+ false
27
27
  end
28
28
 
29
29
  def self.encrypt_data(data, key, cipher, iv)
@@ -1,3 +1,3 @@
1
1
  module Cryptology
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
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.0.0
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: 2017-06-27 00:00:00.000000000 Z
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.1.0
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
- rubyforge_project:
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