confidential_info_manager 0.1.0

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
+ SHA1:
3
+ metadata.gz: 0d02a1d0294bde9a9ed276dd49e7b561a5256395
4
+ data.tar.gz: d54df83c7d3a4e317d3f7f1e172716a538264c6d
5
+ SHA512:
6
+ metadata.gz: 351a0cb3ccc9689f57d91024207311643eeb313e09f2f6d5ebcfe24140cd06be9139f8097bdfbff2ab9cf594734832aeb7a278c207d55b7213b0597049ebe2bb
7
+ data.tar.gz: ae23ce2f57899dac91ebf6956eef2e57f8182aef34ce6137d8c3740b2227c94541234087e94dcd20b6108bee6fb22e34408a7e240aa263c2aac354ba40e6f103
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,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.4
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in confidential_info_manager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 tatsu07
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,53 @@
1
+ # ConfidentialInfoManager
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/confidential_info_manager`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'confidential_info_manager'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install confidential_info_manager
22
+
23
+ ## Usage
24
+
25
+ ### Use as an object
26
+
27
+ ```ruby
28
+ require "confidential_info_manager"
29
+
30
+ raw_data = "string"
31
+
32
+ manager = ConfidentialInfoManager::Core.new("password")
33
+ # encrypt
34
+ encrypt_data = manager.encrypt(raw_data)
35
+ # decrypt
36
+ decrypt_data = manager.decrypt(encrypt_data, String)
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/confidential_info_manager. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "confidential_info_manager"
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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'confidential_info_manager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "confidential_info_manager"
8
+ spec.version = ConfidentialInfoManager::VERSION
9
+ spec.authors = ["tatsu07"]
10
+ spec.email = ["tatsu.tora.1986@gmail.com"]
11
+
12
+ spec.summary = %q{Manage the confidential information}
13
+ spec.description = %q{It provides the encryption and decryption of data . Also , save the encrypted data in JSON or YAML, you can you read .}
14
+ spec.homepage = "https://github.com/tatsu07/confidential_info_manager"
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.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "yard"
26
+ spec.add_development_dependency "yaml"
27
+ spec.add_development_dependency "json"
28
+ end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ require "openssl"
4
+ require "json"
5
+ require "confidential_info_manager/version"
6
+ require "confidential_info_manager/core"
7
+
8
+ module ConfidentialInfoManager
9
+ end
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+
3
+ module ConfidentialInfoManager
4
+
5
+ ##
6
+ # Condidential info manager core class
7
+ # @author tatsunori nishikori <tora.1986.tatsu@gmail.com>
8
+ class Core
9
+
10
+ RANDOM_BYTES = 8.freeze
11
+ ITERATOR_COUNT = 2000.freeze
12
+
13
+ ##
14
+ # constructor
15
+ # @param [String] password
16
+ # @param [String] mode
17
+ # @see OpenSSL::Ciper.ciphers
18
+ def initialize(password, mode="AES-256-CBC")
19
+ generate_encrypter(mode)
20
+ generate_decrypter(mode)
21
+ set_key_and_iv(password)
22
+ end
23
+
24
+ ##
25
+ # encrypt
26
+ # @param [Object] secret data
27
+ # @return [String] encrypted data
28
+ def encrypt(secret_data)
29
+ # convert string
30
+ case secret_data
31
+ when Numeric
32
+ secret_data = secret_data.to_s
33
+ when Hash, Array
34
+ secret_data = Marshal.dump(secret_data)
35
+ end
36
+
37
+ encrypted_data = ""
38
+ encrypted_data << @@encrypter.update(secret_data)
39
+ encrypted_data << @@encrypter.final
40
+ end
41
+
42
+ ##
43
+ # decrypt
44
+ # @param [String] encrypted data
45
+ # @param [Class] type
46
+ # @note String/Fixnum/Bignum/Float/Array/Hash
47
+ # @return [Object] decrypted data
48
+ def decrypt(encrypted_data, type=String)
49
+ decrypted_data = ""
50
+ decrypted_data << @@decrypter.update(encrypted_data)
51
+ decrypted_data << @@decrypter.final
52
+
53
+ if type == Fixnum || type == Bignum
54
+ decrypted_data = decrypted_data.to_i
55
+ elsif type == Float
56
+ decrypted_data = decrypted_data.to_f
57
+ elsif type == Array || type == Hash
58
+ decrypted_data = Marshal.load(decrypted_data)
59
+ end
60
+ decrypted_data
61
+ end
62
+
63
+ private
64
+
65
+ ##
66
+ # setting key and iv
67
+ # @param [String] password
68
+ def set_key_and_iv(password)
69
+ salt = OpenSSL::Random.random_bytes(RANDOM_BYTES)
70
+ # Generated from the password and salt the key and IV in accordance with PKCS#5
71
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(
72
+ password, salt, ITERATOR_COUNT,
73
+ @@encrypter.key_len + @@encrypter.iv_len
74
+ )
75
+ key = key_iv[0, @@encrypter.key_len]
76
+ iv = key_iv[@@encrypter.key_len, @@encrypter.iv_len]
77
+ # Set the key and IV
78
+ @@encrypter.key = key
79
+ @@encrypter.iv = iv
80
+ @@decrypter.key = key
81
+ @@decrypter.iv = iv
82
+ end
83
+
84
+ ##
85
+ # generate encrypter
86
+ # @param [String] mode
87
+ def generate_encrypter(mode)
88
+ @@encrypter = OpenSSL::Cipher.new(mode)
89
+ @@encrypter.encrypt
90
+ end
91
+
92
+ ##
93
+ # generate decrypter
94
+ # @param [String] mode
95
+ def generate_decrypter(mode)
96
+ @@decrypter = OpenSSL::Cipher.new(mode)
97
+ @@decrypter.decrypt
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,3 @@
1
+ module ConfidentialInfoManager
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confidential_info_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tatsu07
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-23 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yaml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: It provides the encryption and decryption of data . Also , save the encrypted
98
+ data in JSON or YAML, you can you read .
99
+ email:
100
+ - tatsu.tora.1986@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - confidential_info_manager.gemspec
116
+ - lib/confidential_info_manager.rb
117
+ - lib/confidential_info_manager/core.rb
118
+ - lib/confidential_info_manager/version.rb
119
+ homepage: https://github.com/tatsu07/confidential_info_manager
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Manage the confidential information
143
+ test_files: []
144
+ has_rdoc: