easy-crypto 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bbf6676bf25e8ec659c4a6aefa5c6e01d05810d89f63d7003b6bfa349511a4d
4
+ data.tar.gz: 5e29d59d20ccd8e532af26936dcd0c5e171de5c925e0703c393c035d6dd99dd4
5
+ SHA512:
6
+ metadata.gz: fa1a514a125fcc58efbaa8036dee9eadae419639720615ed1cc2738bd446140c9237a84c688bb84f2f7a74595747901140edb9c8245cfd3add98bb219dad08f2
7
+ data.tar.gz: 7fd5eba4324cf9e16da567f7e4be5253b0477cbbbcf95c511c71e59e4d2e0bbfa36bac9bff8279832e8a678eeb7c8ca5f7abc02a9d060122e1750ffa653d9530
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle/
3
+ vendor/
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
6
+ deploy:
7
+ provider: rubygems
8
+ api_key:
9
+ secure: im+Pd+6YWK7/xuPdje4NZWVXfbO9cbjrEfDVAzO7rXb4gsOCg5uZLNgdoLvm+h2RiYH90fdDD3GTHChSDFyHjlq4eXyoZTNgAIGkcCuLb3jKdUKjBwS6QpMniD1AwJSQLMQl/E8deCwjkrkOC91PORidpPbVo/M56tRPTSn5MshMX23Z6B6gaaegZTyANaTed91UV8Pkl6p7aPz8QW24fPWHPx6fVktlXM04cTlHH0WloafHAFYAdC5nuolHBD9XcTGvajj7558a/oJR6SjMlU+zKhzjlOFSlXSm6XHImTRSIQ1PnSFRAW1att5Aa8drtm/gvgN9srosiedKryjzsL0bl/gTjlVIv0i6gpF5/pnfxGN+n16GwSkBLctUUFz1aDQ1NDk7+Ob+HmB8OaoUsAfSCZ/GKgbjrjuP4dZIWmpTbjPiWqir2vid6qm+RSDm2vZ4GpatXfbuSWh1t9bKSVQSKsT0b5FMrowI4d69wvUFSECbZK0RvASiG/q9/GSj5cc9jboqAD3koKxvsqusoKBdOcPWYW1t9BFSKrGwmRrHQvUXUxqj+UwHQK6QMeYgOIAbhDCVTVSlLbrRxzX11f3GbMiU8ztQDb2CM+kI/IB2cxG1GtMnwYVxDTAV0Mnt2AvmBG3JFzg6mVE6JkExnN7uq9NE3aIVwGPillYUqI8=
10
+ gemspec: easy-crypto.gemspec
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ easy-crypto (0.0.1)
5
+ openssl (~> 2.1.1, >= 2.1.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ openssl (2.1.1)
12
+ rake (10.5.0)
13
+ rspec (3.7.0)
14
+ rspec-core (~> 3.7.0)
15
+ rspec-expectations (~> 3.7.0)
16
+ rspec-mocks (~> 3.7.0)
17
+ rspec-core (3.7.1)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-expectations (3.7.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-mocks (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-support (3.7.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.16)
32
+ easy-crypto!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Istvan Szenasi
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,27 @@
1
+ # EasyCrypto
2
+
3
+ Provides simple wrappers around the openssl crypto implementation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'easy-crypto'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install easy-crypto
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'easycrypto/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'easy-crypto'
7
+ spec.version = EasyCrypto::VERSION
8
+ spec.authors = ['Emarsys Security']
9
+ spec.email = ['security@emarsys.com']
10
+
11
+ spec.summary = 'Provides simple wrappers around openssl crypto implementation.'
12
+ spec.homepage = 'https://github.com/emartech/ruby-easy-crypto'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.16'
19
+ spec.add_development_dependency 'rake', '~> 10.0'
20
+ spec.add_development_dependency 'rspec', '~> 3.0'
21
+
22
+ spec.add_runtime_dependency 'openssl', '~> 2.1.1', '>= 2.1.1'
23
+ end
data/lib/easycrypto.rb ADDED
@@ -0,0 +1,5 @@
1
+ module EasyCrypto
2
+ require 'easycrypto/version'
3
+ require 'easycrypto/key'
4
+ require 'easycrypto/crypto'
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+ require_relative 'key'
4
+
5
+ module EasyCrypto
6
+ class Crypto
7
+ KEY_BITS = 256
8
+ AES_MODE = :GCM
9
+ IV_LEN = 12
10
+
11
+ def encrypt_with_key(key, plaintext)
12
+ validate_key_type(key)
13
+
14
+ iv = OpenSSL::Random.random_bytes(Crypto::IV_LEN)
15
+ cipher = create_cipher(key, iv)
16
+
17
+ encrypted = cipher.update(plaintext) + cipher.final
18
+
19
+ Base64.encode64(key.salt + iv + encrypted + cipher.auth_tag)
20
+ end
21
+
22
+ private
23
+
24
+ def validate_key_type(key)
25
+ raise TypeError 'key must have Key type' unless key.is_a?(EasyCrypto::Key)
26
+ end
27
+
28
+ def create_cipher(key, iv)
29
+ cipher = OpenSSL::Cipher::AES.new(Crypto::KEY_BITS, Crypto::AES_MODE).encrypt
30
+ cipher.key = key.key
31
+ cipher.iv = iv
32
+ cipher
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+
5
+ module EasyCrypto
6
+ class Key
7
+ ITERATION_COUNT = 10_000
8
+ KEY_LENGTH = 32
9
+ HASH_ALGO = 'sha256'
10
+
11
+ attr_reader :key, :salt
12
+
13
+ def initialize(key, salt)
14
+ @key = key
15
+ @salt = salt
16
+ end
17
+
18
+ def self.generate(password, salt_length)
19
+ salt = OpenSSL::Random.random_bytes(salt_length)
20
+ key = OpenSSL::KDF.pbkdf2_hmac(
21
+ password,
22
+ salt: salt,
23
+ iterations: Key::ITERATION_COUNT,
24
+ length: Key::KEY_LENGTH,
25
+ hash: Key::HASH_ALGO
26
+ )
27
+
28
+ new(key, salt)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasyCrypto
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'easycrypto'
2
+
3
+ RSpec.describe EasyCrypto::Crypto do
4
+ it 'has a version number' do
5
+ expect(EasyCrypto::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ RSpec.configure do |config|
5
+ config.disable_monkey_patching!
6
+
7
+ config.expect_with :rspec do |c|
8
+ c.syntax = :expect
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-crypto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Emarsys Security
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: openssl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.1
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.1.1
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: 2.1.1
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.1.1
75
+ description:
76
+ email:
77
+ - security@emarsys.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - easy-crypto.gemspec
90
+ - lib/easycrypto.rb
91
+ - lib/easycrypto/crypto.rb
92
+ - lib/easycrypto/key.rb
93
+ - lib/easycrypto/version.rb
94
+ - spec/easycrypto/crypto_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/emartech/ruby-easy-crypto
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.7
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Provides simple wrappers around openssl crypto implementation.
120
+ test_files: []