musa 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a50449ca9a0c031e8686ae8a3c4ac6009a2f375
4
+ data.tar.gz: c36479f46ec17270fcffe6922f1a5d9083a9f94d
5
+ SHA512:
6
+ metadata.gz: 90d70214ae867dd321b50cbc33fb9aa4801c4726995714b08b9f38aa7e4c1313840d8467c6bfda47f9b98d1df10f2efbc6bd8a091e519fa4dedc42110018c7a0
7
+ data.tar.gz: e31c4b5838e5dc9b8a043d9cf4c4a4f4cfa5b3cdf1982df5a484acbca4172c8f8656cfd9ca0ab9848463610621d44e17fdb11ef44ddfb633287474e5edb27c23
@@ -0,0 +1,11 @@
1
+ ---
2
+ engines:
3
+ rubocop:
4
+ enabled: true
5
+
6
+ ratings:
7
+ paths:
8
+ - ".rb"
9
+
10
+ exclude_paths:
11
+ - musa.gemspec
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ spec/fixtures/encrypted_test.txt
11
+ spec/fixtures/decrypted_test.txt
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2.2
7
+ - ruby-head
8
+ - jruby-9.0.3.0
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: 1.9.3
12
+ - rvm: ruby-head
13
+ - rvm: jruby-9.0.3.0
14
+ fast_finish: true
15
+ before_install: gem install bundler -v 1.11.2
16
+ addons:
17
+ code_climate:
18
+ repo_token: cf6624be91309ad923ff8be91fb870c3ec67465a144927903286028313c7fc37
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at chris@enytc.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in musa.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test
@@ -0,0 +1,24 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2015, Christopher EnyTC
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the "Software"), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,101 @@
1
+ # Musa [![Build Status](https://img.shields.io/travis/chrisenytc/musa/master.svg)](http://travis-ci.org/chrisenytc/musa) [![GEM version](https://img.shields.io/gem/v/musa.svg)](https://rubygems.org/gems/musa) [![Gem Downloads](https://img.shields.io/gem/dt/musa.svg)](https://rubygems.org/gems/musa) [![Code Climate](https://img.shields.io/codeclimate/github/chrisenytc/musa.svg)](https://codeclimate.com/github/chrisenytc/musa) [![Coverage](https://img.shields.io/codeclimate/coverage/github/chrisenytc/musa.svg)](https://codeclimate.com/github/chrisenytc/musa) [![Dependencies](https://img.shields.io/gemnasium/chrisenytc/musa.svg)](https://github.com/chrisenytc/musa) [![Tips](https://img.shields.io/gratipay/musa.svg)](https://gratipay.com/musa/)
2
+
3
+ > A awesome tool to manage sensitive environment variables in your development environment
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'musa'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install musa
20
+
21
+ ## Usage
22
+
23
+ #### Encrypt a string
24
+
25
+ ```ruby
26
+ require 'musa'
27
+
28
+ sensitive_data = 'My top secret data'
29
+ key = '7f6de8pg52s7135ebhmjk6qzmbsms3eg' # Key length need to be greater than or equal to 32
30
+
31
+ encrypted_data = Musa::Encryption::encrypt key, sensitive_data
32
+ ```
33
+
34
+ #### Decrypt a string
35
+
36
+ ```ruby
37
+ require 'musa'
38
+
39
+ encrypted_data = 'ANdNxjWh0e7QqdVT5WZFlyynZYeB95z/TGFY8yBmBtY=\n'
40
+ key = '7f6de8pg52s7135ebhmjk6qzmbsms3eg' # Key length need to be greater than or equal to 32
41
+
42
+ decrypted_data = Musa::Decryption::decrypt key, encrypted_data
43
+ ```
44
+
45
+ #### Encrypt a file
46
+
47
+ ```ruby
48
+ require 'musa'
49
+
50
+ key = '7f6de8pg52s7135ebhmjk6qzmbsms3eg' # Key length need to be greater than or equal to 32
51
+
52
+ encrypted_data = Musa::Encryption::encrypt_file key, 'sensitive_file.txt', 'encrypted_data.txt'
53
+ ```
54
+
55
+ #### Decrypt a file
56
+
57
+ ```ruby
58
+ require 'musa'
59
+
60
+ key = '7f6de8pg52s7135ebhmjk6qzmbsms3eg' # Key length need to be greater than or equal to 32
61
+
62
+ decrypted_data = Musa::Decryption::decrypt_file key, 'encrypted_data.txt', 'decrypted_data.txt'
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/chrisenytc/musa](https://github.com/chrisenytc/musa). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+
69
+ 1. Fork it [chrisenytc/musa](https://github.com/chrisenytc/musa/fork)
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am "Add some feature"`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
74
+
75
+ ## License
76
+
77
+ The MIT License
78
+
79
+ Copyright (c) 2015, Christopher EnyTC
80
+
81
+ Permission is hereby granted, free of charge, to any person
82
+ obtaining a copy of this software and associated documentation
83
+ files (the "Software"), to deal in the Software without
84
+ restriction, including without limitation the rights to use,
85
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
86
+ copies of the Software, and to permit persons to whom the
87
+ Software is furnished to do so, subject to the following
88
+ conditions:
89
+
90
+ The above copyright notice and this permission notice shall be
91
+ included in all copies or substantial portions of the Software.
92
+
93
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
94
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
95
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
96
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
97
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
98
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
99
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
100
+ OTHER DEALINGS IN THE SOFTWARE.
101
+
@@ -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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'musa'
5
+ require 'irb'
6
+
7
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,10 @@
1
+ require 'musa/version'
2
+ require 'musa/error'
3
+ require 'musa/encrypt'
4
+ require 'musa/decrypt'
5
+
6
+ ##
7
+ # Musa main module
8
+ module Musa
9
+ ALGORITHM = 'AES-256-CBC'
10
+ end
@@ -0,0 +1,40 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+
4
+ module Musa
5
+ ##
6
+ # Musa decryption class
7
+ class Decryption
8
+ def self.decrypt(key, encrypted_data)
9
+ # Check length
10
+ fail Musa::Error::ShortKey if key.size < 32
11
+ # Generate cipher
12
+ cipher = OpenSSL::Cipher.new ALGORITHM
13
+ # Start decryption
14
+ cipher.decrypt
15
+ # Add cipher key
16
+ cipher.key = key
17
+ # Define temporary data
18
+ tempdata = Base64.decode64 encrypted_data
19
+ # Add encrypted data to cipher
20
+ crypt = cipher.update tempdata
21
+ # Finish decryption
22
+ crypt << cipher.final
23
+ end
24
+
25
+ def self.decrypt_file(key, encrypted_path, file_output)
26
+ # Raise a error if file is not found
27
+ fail Musa::Error::FileNotFound unless File.exist?(encrypted_path)
28
+ # Read encrypted source
29
+ file = File.read encrypted_path
30
+ # Decrypt encrypted source
31
+ decrypted_data = Musa::Decryption.decrypt key, file
32
+ # Write decrypted data to output file
33
+ File.open(file_output, 'a+') do |f|
34
+ f << decrypted_data
35
+ end
36
+ # Return decrypted data
37
+ decrypted_data
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+
4
+ module Musa
5
+ ##
6
+ # Musa encryption class
7
+ class Encryption
8
+ def self.encrypt(key, data)
9
+ # Raise a error if key length is less than 32
10
+ fail Musa::Error::ShortKey if key.size < 32
11
+ # Generate cipher
12
+ cipher = OpenSSL::Cipher.new ALGORITHM
13
+ # Start encryption
14
+ cipher.encrypt
15
+ # Add cipher key
16
+ cipher.key = key
17
+ # Add data to the cipher
18
+ crypt = cipher.update(data) + cipher.final
19
+ # Encode cipher result
20
+ Base64.encode64 crypt
21
+ end
22
+
23
+ def self.encrypt_file(key, file_path, file_output)
24
+ # Raise a error if file is not found
25
+ fail Musa::Error::FileNotFound unless File.exist?(file_path)
26
+ # Read source
27
+ file = File.read file_path
28
+ # Encrypt source
29
+ encrypted_data = Musa::Encryption.encrypt key, file
30
+ # Write encrypted data to output file
31
+ File.open(file_output, 'a+') do |f|
32
+ f << encrypted_data
33
+ end
34
+ # Return encrypted data
35
+ encrypted_data
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ module Musa
2
+ module Error
3
+ ##
4
+ # Musa error class
5
+ class Error < StandardError
6
+ def initialize(msg = nil)
7
+ @message = msg
8
+ end
9
+
10
+ attr_reader :message
11
+ end
12
+
13
+ ##
14
+ # Musa efile not found class
15
+ class FileNotFound < Error
16
+ def message
17
+ 'Cannot find the file path.'
18
+ end
19
+ end
20
+
21
+ ##
22
+ # Musa short key class
23
+ class ShortKey < Error
24
+ def message
25
+ 'Key need to have length greater than or equal to 32.'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ ##
2
+ # Musa version
3
+ module Musa
4
+ VERSION = '0.1.0'
5
+ end
@@ -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 'musa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'musa'
8
+ spec.version = Musa::VERSION
9
+ spec.authors = ['Christopher EnyTC']
10
+ spec.email = ['chris@enytc.com']
11
+
12
+ spec.summary = 'Encrypt and decrypt files with aes-256-cbc.'
13
+ spec.description = 'A gem to encrypt and decrypt files with aes-256-cbc.'
14
+ spec.homepage = 'https://github.com/chrisenytc/musa'
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.11'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'faker', '~> 1.6'
26
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: musa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christopher EnyTC
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: faker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ description: A gem to encrypt and decrypt files with aes-256-cbc.
70
+ email:
71
+ - chris@enytc.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".codeclimate.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/musa.rb
88
+ - lib/musa/decrypt.rb
89
+ - lib/musa/encrypt.rb
90
+ - lib/musa/error.rb
91
+ - lib/musa/version.rb
92
+ - musa.gemspec
93
+ homepage: https://github.com/chrisenytc/musa
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Encrypt and decrypt files with aes-256-cbc.
117
+ test_files: []