cryptology 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be3f956af95f13d3a1c53155ab98651794402a38
4
+ data.tar.gz: 45481cf1204233fa83b4647b8ae9f7f233170af6
5
+ SHA512:
6
+ metadata.gz: a894dff57ff6c129010e6be2922425bcf0fa91f8873150f902a17da524460cb488b364e3df589a55967f674d4514430f8b2b38d5940e35bcb8d4e18d5d602ad1
7
+ data.tar.gz: 79f2eae716e4011b28e842caea3f104e66f2341521e8fe9d514b739efc205debeb153143c6e0bcf8161fe346eaf7da45f8a8fc845a062cb977b860e06659f71f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.7
6
+ - 2.2.3
7
+
8
+ sudo: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 1.0.0 (2015-12-07)
2
+
3
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cryptology.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dmitriy Tarasov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Cryptology
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cryptology.svg)](http://badge.fury.io/rb/cryptology)
4
+ [![Build Status](https://travis-ci.org/rubysamurai/cryptology.svg?branch=master)](https://travis-ci.org/rubysamurai/cryptology)
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.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'cryptology'
14
+ ```
15
+
16
+ Save `Gemfile` and execute `bundle` command to install the gem.
17
+
18
+ Or to install it yourself run this command:
19
+
20
+ ```
21
+ $ gem install cryptology
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ # Encrypting
28
+ Cryptology.encrypt(data, key, algorithm, iv)
29
+
30
+ # Decrypting
31
+ Cryptology.decrypt(data, key, algorithm, iv)
32
+ ```
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
40
+
41
+ Example:
42
+
43
+ ```ruby
44
+ # Data to encrypt (required)
45
+ data = 'Very, very confidential data'
46
+ # Secure key for encryption (required)
47
+ key = 'veryLongAndSecurePassword_6154309'
48
+ # Use Blowfish algorithm in CBC mode (optional)
49
+ algorithm = 'BF-CBC'
50
+ # Initialization vector for BF-CBC (optional)
51
+ iv = OpenSSL::Cipher::Cipher.new(algorithm).random_iv
52
+
53
+ # Encrypt our data
54
+ encrypted = Cryptology.encrypt(data, key, algorithm, iv)
55
+
56
+ # Decrypt our data
57
+ plain = Cryptology.decrypt(data, key, algorithm, iv)
58
+
59
+ ```
60
+
61
+ ### Cipher algorithms
62
+
63
+ To get a list of available cipher algorithms in your environment run this command:
64
+
65
+ ```
66
+ $ openssl list-cipher-algorithms
67
+ ```
68
+
69
+ or this Ruby code:
70
+
71
+ ```ruby
72
+ require 'openssl'
73
+ puts OpenSSL::Cipher.ciphers
74
+ ```
75
+
76
+ ## Contributing
77
+
78
+ 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.
79
+
80
+ ## License
81
+
82
+ `Cryptology` © Dmitriy Tarasov, 2015. Released under the [MIT](https://github.com/rubysamurai/cryptology/blob/master/LICENSE.txt) license.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ task default: :spec
4
+ RSpec::Core::RakeTask.new
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cryptology'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cryptology/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cryptology'
8
+ spec.version = Cryptology::VERSION
9
+ spec.authors = ['Dmitriy Tarasov']
10
+ spec.email = ['info@rubysamurai.com']
11
+
12
+ spec.summary = 'Wrapper for symmetric encryption and decryption using any algorithm supported by OpenSSL'
13
+ spec.description = 'Wrapper for symmetric encryption and decryption using any algorithm supported by OpenSSL'
14
+ spec.homepage = 'https://github.com/rubysamurai/cryptology'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 2.0.0'
23
+
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.3'
26
+ end
data/lib/cryptology.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'cryptology/version'
2
+ require 'openssl'
3
+ require 'base64'
4
+
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)
8
+ ::Base64.encode64(encrypted)
9
+ end
10
+
11
+ def self.decrypt(data, key, algorithm = 'AES-256-CBC', iv = nil)
12
+ base64_decoded = ::Base64.decode64(data.to_s)
13
+ decrypt_data(base64_decoded, digest(key), algorithm, iv)
14
+ .force_encoding('UTF-8').encode
15
+ end
16
+
17
+ private
18
+
19
+ def self.encrypt_data(data, key, algorithm, iv)
20
+ cipher = ::OpenSSL::Cipher::Cipher.new(algorithm)
21
+ cipher.encrypt
22
+ cipher.key = key
23
+ cipher.iv = iv
24
+ cipher.update(data) + cipher.final
25
+ end
26
+
27
+ def self.decrypt_data(encrypted_data, key, algorithm, iv)
28
+ decipher = ::OpenSSL::Cipher::Cipher.new(algorithm)
29
+ decipher.decrypt
30
+ decipher.key = key
31
+ decipher.iv = iv
32
+ decipher.update(encrypted_data) + decipher.final
33
+ end
34
+
35
+ def self.digest(key)
36
+ ::OpenSSL::Digest::SHA256.digest(key)
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Cryptology
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptology
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitriy Tarasov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ description: Wrapper for symmetric encryption and decryption using any algorithm supported
42
+ by OpenSSL
43
+ email:
44
+ - info@rubysamurai.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - CHANGELOG.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - cryptology.gemspec
60
+ - lib/cryptology.rb
61
+ - lib/cryptology/version.rb
62
+ homepage: https://github.com/rubysamurai/cryptology
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.0.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.8
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Wrapper for symmetric encryption and decryption using any algorithm supported
86
+ by OpenSSL
87
+ test_files: []