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 +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +5 -0
- data/README.md +17 -17
- data/cryptology.gemspec +1 -1
- data/lib/cryptology.rb +11 -11
- data/lib/cryptology/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ffdef922d38150c58aace752ca1656791678a5
|
4
|
+
data.tar.gz: 6e74ff79379bb8d0242f1465a2072ccbab1666eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8845e0fbfa4e0b69e36a7e18a4c896737f72731f8c703c108e1772503d987a8d16a82fd6665cb604b6e8743a319c8598b6674e746b5b68c94f4ad542b536817b
|
7
|
+
data.tar.gz: f031d742a21a2c42c871bb8b7aa284effc30f5053925d753c3f3fb3f8f629365195370714802dbc8e7bd40b1190fef3a9450d71636122f0ca4ea44ff72a182f2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Cryptology
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/cryptology.svg)](
|
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
|
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,
|
28
|
+
Cryptology.encrypt(data: data, key: key, cipher: cipher, iv: iv)
|
29
29
|
|
30
30
|
# Decrypting
|
31
|
-
Cryptology.decrypt(data, key,
|
31
|
+
Cryptology.decrypt(data: data, key: key, cipher: cipher, iv: iv)
|
32
32
|
```
|
33
33
|
|
34
|
-
Argument
|
35
|
-
|
36
|
-
data
|
37
|
-
key
|
38
|
-
|
39
|
-
iv
|
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
|
49
|
-
|
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(
|
51
|
+
iv = OpenSSL::Cipher::Cipher.new(cipher).random_iv
|
52
52
|
|
53
53
|
# Encrypt our data
|
54
|
-
encrypted = Cryptology.encrypt(data, key,
|
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,
|
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.
|
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
|
7
|
-
encrypted = encrypt_data(data.to_s, digest(key),
|
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
|
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),
|
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,
|
20
|
-
cipher = ::OpenSSL::Cipher::Cipher.new(
|
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
|
23
|
+
cipher.iv = iv unless iv.nil?
|
24
24
|
cipher.update(data) + cipher.final
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.decrypt_data(
|
28
|
-
decipher = ::OpenSSL::Cipher::Cipher.new(
|
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
|
32
|
-
decipher.update(
|
31
|
+
decipher.iv = iv unless iv.nil?
|
32
|
+
decipher.update(data) + decipher.final
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.digest(key)
|
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: 1.0
|
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-
|
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.
|
74
|
+
version: 2.1.0
|
75
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - ">="
|