cryptology 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6d8652577b9efbf08654071baa5eeaf5b7bab7d
4
- data.tar.gz: 3b55e70aae9c511960b58c723e723ed55ebf217c
3
+ metadata.gz: 87ffdef922d38150c58aace752ca1656791678a5
4
+ data.tar.gz: 6e74ff79379bb8d0242f1465a2072ccbab1666eb
5
5
  SHA512:
6
- metadata.gz: 7d2fa0167bb97234782fde940d707a30c3eb4bd9bd56bc1ba54ff34ab7bdd8155be35525e803f15b9be567665ab024be5b7f57eade759260a1395aa1d9b0a3f9
7
- data.tar.gz: 76c7f040b484a1a051c739211dc0a4737ae68066d3bbef5fd4a229040d7a31c349799cce50b2e1efb17116d1636f97b1740bd9f0bcf9e567c203a54a9e522c5e
6
+ metadata.gz: 8845e0fbfa4e0b69e36a7e18a4c896737f72731f8c703c108e1772503d987a8d16a82fd6665cb604b6e8743a319c8598b6674e746b5b68c94f4ad542b536817b
7
+ data.tar.gz: f031d742a21a2c42c871bb8b7aa284effc30f5053925d753c3f3fb3f8f629365195370714802dbc8e7bd40b1190fef3a9450d71636122f0ca4ea44ff72a182f2
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.0.0
5
4
  - 2.1.7
6
5
  - 2.2.3
7
6
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.1.0 (2015-12-08)
2
+
3
+ - Improvement: Switch to keyword arguments
4
+ - Ruby Versioning: Drop support for Ruby 2.0
5
+
1
6
  ## 1.0.1 (2015-12-08)
2
7
 
3
8
  - Bug Fix: Allow iv to be nil
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Cryptology
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/cryptology.svg)](http://badge.fury.io/rb/cryptology)
3
+ [![Gem Version](https://badge.fury.io/rb/cryptology.svg)](https://badge.fury.io/rb/cryptology)
4
4
  [![Build Status](https://travis-ci.org/rubysamurai/cryptology.svg?branch=master)](https://travis-ci.org/rubysamurai/cryptology)
5
5
 
6
- `Cryptology` is a wrapper for encryption and decryption in Ruby. Supports all 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. Supports all cipher algorithms, that are available in installed version of OpenSSL. By default `AES-256-CBC` is used.
7
7
 
8
8
  ## Installation
9
9
 
@@ -13,9 +13,9 @@ Add this line to your application's Gemfile:
13
13
  gem 'cryptology'
14
14
  ```
15
15
 
16
- Save `Gemfile` and execute `bundle` command to install the gem.
16
+ Save `Gemfile` and execute `$ bundle` command to install the gem.
17
17
 
18
- Or to install it yourself run this command:
18
+ Or to install it yourself run this command:
19
19
 
20
20
  ```
21
21
  $ gem install cryptology
@@ -25,18 +25,18 @@ $ gem install cryptology
25
25
 
26
26
  ```ruby
27
27
  # Encrypting
28
- Cryptology.encrypt(data, key, algorithm, iv)
28
+ Cryptology.encrypt(data: data, key: key, cipher: cipher, iv: iv)
29
29
 
30
30
  # Decrypting
31
- Cryptology.decrypt(data, key, algorithm, iv)
31
+ Cryptology.decrypt(data: data, key: key, cipher: cipher, iv: iv)
32
32
  ```
33
33
 
34
- Argument | Required? | Default | Comment
35
- ----------|-----------|---------------|-------------
36
- data | **Yes** | n/a | Data to encrypt or decrypt
37
- key | **Yes** | n/a | Secure key for encryption and decryption
38
- algorithm | *No* | `AES-256-CBC` | Cipher algorithm
39
- iv | *No* | `nil` | Initialization vector for CBC, CFB, CTR, OFB modes
34
+ Argument | Required? | Default | Comment
35
+ ---------|-----------|---------------|-------------
36
+ data | **Yes** | n/a | Data to encrypt or decrypt
37
+ key | **Yes** | n/a | Secure key for encryption and decryption
38
+ cipher | *No* | `AES-256-CBC` | Cipher algorithm
39
+ iv | *No* | `nil` | Initialization vector for CBC, CFB, CTR, OFB modes
40
40
 
41
41
  Example:
42
42
 
@@ -45,16 +45,16 @@ Example:
45
45
  data = 'Very, very confidential data'
46
46
  # Secure key for encryption (required)
47
47
  key = 'veryLongAndSecurePassword_6154309'
48
- # Use Blowfish algorithm in CBC mode (optional)
49
- algorithm = 'BF-CBC'
48
+ # Use Blowfish cipher in CBC mode (optional)
49
+ cipher = 'BF-CBC'
50
50
  # Initialization vector for BF-CBC (optional)
51
- iv = OpenSSL::Cipher::Cipher.new(algorithm).random_iv
51
+ iv = OpenSSL::Cipher::Cipher.new(cipher).random_iv
52
52
 
53
53
  # Encrypt our data
54
- encrypted = Cryptology.encrypt(data, key, algorithm, iv)
54
+ encrypted = Cryptology.encrypt(data: data, key: key, cipher: cipher, iv: iv)
55
55
 
56
56
  # Decrypt our data
57
- plain = Cryptology.decrypt(encrypted, key, algorithm, iv)
57
+ plain = Cryptology.decrypt(data: encrypted, key: key, cipher: cipher, iv: iv)
58
58
 
59
59
  ```
60
60
 
data/cryptology.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.required_ruby_version = '>= 2.0.0'
22
+ spec.required_ruby_version = '>= 2.1.0'
23
23
 
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec', '~> 3.3'
data/lib/cryptology.rb CHANGED
@@ -3,33 +3,33 @@ require 'openssl'
3
3
  require 'base64'
4
4
 
5
5
  module Cryptology
6
- def self.encrypt(data, key, algorithm = 'AES-256-CBC', iv = nil)
7
- encrypted = encrypt_data(data.to_s, digest(key), algorithm, iv)
6
+ def self.encrypt(data:, key:, cipher: 'AES-256-CBC', iv: nil)
7
+ encrypted = encrypt_data(data.to_s, digest(key), cipher, iv)
8
8
  ::Base64.encode64(encrypted)
9
9
  end
10
10
 
11
- def self.decrypt(data, key, algorithm = 'AES-256-CBC', iv = nil)
11
+ def self.decrypt(data:, key:, cipher: 'AES-256-CBC', iv: nil)
12
12
  base64_decoded = ::Base64.decode64(data.to_s)
13
- decrypt_data(base64_decoded, digest(key), algorithm, iv)
13
+ decrypt_data(base64_decoded, digest(key), cipher, iv)
14
14
  .force_encoding('UTF-8').encode
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def self.encrypt_data(data, key, algorithm, iv)
20
- cipher = ::OpenSSL::Cipher::Cipher.new(algorithm)
19
+ def self.encrypt_data(data, key, cipher, iv)
20
+ cipher = ::OpenSSL::Cipher::Cipher.new(cipher)
21
21
  cipher.encrypt
22
22
  cipher.key = key
23
- cipher.iv = iv unless iv.nil?
23
+ cipher.iv = iv unless iv.nil?
24
24
  cipher.update(data) + cipher.final
25
25
  end
26
26
 
27
- def self.decrypt_data(encrypted_data, key, algorithm, iv)
28
- decipher = ::OpenSSL::Cipher::Cipher.new(algorithm)
27
+ def self.decrypt_data(data, key, cipher, iv)
28
+ decipher = ::OpenSSL::Cipher::Cipher.new(cipher)
29
29
  decipher.decrypt
30
30
  decipher.key = key
31
- decipher.iv = iv unless iv.nil?
32
- decipher.update(encrypted_data) + decipher.final
31
+ decipher.iv = iv unless iv.nil?
32
+ decipher.update(data) + decipher.final
33
33
  end
34
34
 
35
35
  def self.digest(key)
@@ -1,3 +1,3 @@
1
1
  module Cryptology
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
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: 1.0.1
4
+ version: 1.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: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -71,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 2.0.0
74
+ version: 2.1.0
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - ">="