sekreti 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 108dc200e277cc9f254211e0d92c30783ab5f8a721da05865519c45f2a641022
4
+ data.tar.gz: 7ab731092115d74199651c9cd2abf3068852f457a52034cc18cd20157947c996
5
+ SHA512:
6
+ metadata.gz: 90f91b9dccca63e2e3624eca0b9ed4db17af7564b87cf596fd50118e33b90ae90b016d455e0e7fc5f39f52d014a70d3ebb7fcb056505a4ed4078f6e4e8b2f454
7
+ data.tar.gz: 2ede38a4586530a9ac6d4e27241f7d52cbd3e2e17a872425dea65e0284f0fad6f982866daadb882e3ff1e1f7d0770d2dcf153609f53f588c1fddf538d4cffd59
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .vendor/
10
+ Gemfile.lock
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,75 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gautierfrancois@outlook.com
59
+ . All
60
+ complaints will be reviewed and investigated and will result in a response that
61
+ is deemed necessary and appropriate to the circumstances. The project team is
62
+ obligated to maintain confidentiality with regard to the reporter of an incident.
63
+ Further details of specific enforcement policies may be posted separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ ## Attribution
70
+
71
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72
+ available at [http://contributor-covenant.org/version/1/4][version]
73
+
74
+ [homepage]: http://contributor-covenant.org
75
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sekret.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 atille
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,87 @@
1
+ # sekreti
2
+
3
+ sekreti is an easy-to use yet minimal Gem to encrypt and decrypt file. It is based upon OpenSSL and intends to be as easy as possible on usage.
4
+ \
5
+ At the moment, sekreti only supports AES-128-CBC encryption protocol, but some other could be added in the future.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sekreti'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sekreti
22
+
23
+ ## Usage
24
+
25
+ From a Ruby file, basic steps are :
26
+
27
+
28
+ ### Encrypt a file
29
+ ```ruby
30
+ require "sekreti"
31
+
32
+ # Encrypt a file
33
+ encrypt = sekreti::Crypt.new
34
+ encrypt.file = "./decrypted_file.txt"
35
+ encrypt.output_file = "./encrypted_output.txt"
36
+ encrypt.salt = "aaaaaaaaaaaaaaaa" # a 16 bytes long encryption key
37
+
38
+ # Validate that everything is ok
39
+
40
+ encrypt.file? # true
41
+ encrypt.output_file? # true
42
+ encrypt.salt? # true
43
+
44
+ # Encrypt the file
45
+ encrypt.status? # false
46
+ encrypt.encrypt! # returns true
47
+ encrypt.status? # true
48
+ ```
49
+
50
+ ### Decrypt a file
51
+ ```ruby
52
+ require "sekreti"
53
+
54
+ decrypt = sekreti::Crypt.new
55
+ decrypt.file = "./encrypted_file.txt"
56
+ decrypt.output_file = "./decrypted_output.txt"
57
+ decrypt.salt = "aaaaaaaaaaaaaaaa" # a 16 bytes long decryption key
58
+
59
+ # Validate that everything is ok
60
+
61
+ decrypt.file? # true
62
+ decrypt.output_file? # true
63
+ decrypt.salt? # true
64
+
65
+ # Decrypt the file
66
+ decrypt.status? # false
67
+ decrypt.decrypt! # returns true
68
+ decrypt.status? # true
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ 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).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sekreti. 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.
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the sekreti project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sekreti/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "sekreti"
4
+ require "securerandom"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ namespace :sekreti do
10
+ desc "Encrypt a file using sekreti gem"
11
+ task :encrypt do
12
+ sekreti = sekreti::Crypt.new
13
+ sekreti.file = ENV["sekreti_FILE"]
14
+ sekreti.output_file = ENV["sekreti_OUTPUT"]
15
+ unless ENV["sekreti_KEY"]
16
+ sekreti.salt = SecureRandom.hex(32)[0..15]
17
+ else
18
+ sekreti.salt = ENV["sekreti_KEY"]
19
+ end
20
+
21
+ if sekreti.encrypt!
22
+ puts "File encrypted. Decryption key is #{sekreti.salt}"
23
+ end
24
+ end
25
+
26
+ desc "Decrypt a file using sekreti gem"
27
+ task :decrypt do
28
+ sekreti = sekreti::Crypt.new
29
+ sekreti.file = ENV["sekreti_FILE"]
30
+ sekreti.outpuf_file = ENV["sekreti_OUTPUT"]
31
+ sekreti.salt = ENV["sekreti_KEY"]
32
+ if sekreti.decrypt!
33
+ puts "File decrypted."
34
+ end
35
+ end
36
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sekreti"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ require "openssl"
2
+ module Sekreti
3
+ # Main class performing operations.
4
+ class Core
5
+ # Encrypts a file with AES-128-CBC cipher, using
6
+ # a submitted 16 bytes string.
7
+ # @param options [Hash] submitted parameters
8
+ # @return boolean
9
+ def self.encrypt!(options)
10
+ cipher = OpenSSL::Cipher.new("AES-128-CBC")
11
+ cipher.encrypt
12
+ cipher.key = options[:salt]
13
+
14
+ outf = File.open(
15
+ options[:output_file],
16
+ 'wb'
17
+ )
18
+
19
+ encrypted = cipher.update(File.read(options[:path])) + cipher.final
20
+ outf.write(encrypted)
21
+
22
+ return true
23
+ end
24
+
25
+ # Decrypts a file with a submitted key.
26
+ # @param options [Hash] submitted parameters
27
+ # @return boolean
28
+ def self.decrypt!(options)
29
+ decipher = OpenSSL::Cipher.new("AES-128-CBC")
30
+ decipher.decrypt
31
+ decipher.key = options[:salt]
32
+
33
+ f = File.open(options[:output_file], 'w')
34
+ decrypted = decipher.update(File.read(options[:path])) + decipher.final
35
+ f.write(decrypted)
36
+
37
+ return true
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,127 @@
1
+ require_relative "./core"
2
+
3
+ module Sekreti
4
+ # Access helper to call the encryption and decryption
5
+ # actions.
6
+ class Crypt
7
+ def initialize(options={})
8
+ @options = options
9
+ end
10
+
11
+ # Returns entry file
12
+ # @return entry file
13
+ def file
14
+ @options[:path]
15
+ end
16
+
17
+ # Defines entry file
18
+ # @param path [String] relative or absolute path to
19
+ # entry file.
20
+ def file=(path)
21
+ @options[:path] = path
22
+ end
23
+
24
+ # Returns true if entry file is defined and
25
+ # exists.
26
+ # @return boolean
27
+ def file?
28
+ unless @options.key?(:path)
29
+ return false
30
+ end
31
+
32
+ unless File.file? @options[:path]
33
+ return false
34
+ end
35
+
36
+ true
37
+ end
38
+
39
+ # Returns output file parameter
40
+ # @return output file parameter
41
+ def output_file
42
+ @options[:output_file]
43
+ end
44
+
45
+ # Defines the output file
46
+ # @param output_file [String] relative or absolute path
47
+ # to output file.
48
+ def output_file=(output_file)
49
+ @options[:output_file] = output_file
50
+ end
51
+
52
+ # Returns true if the output file is defined and
53
+ # it doesn't exist yet.
54
+ # @return bool
55
+ def output_file?
56
+ unless @options.key?(:output_file)
57
+ return false
58
+ end
59
+
60
+ if File.file? @options[:output_file]
61
+ return false
62
+ end
63
+
64
+ true
65
+ end
66
+
67
+ # Returns the encryption salt
68
+ # @return encryption salt
69
+ def salt
70
+ @options[:salt]
71
+ end
72
+
73
+ # Set the encryption salt
74
+ # @param salt [String] 16 bytes string
75
+ # @return boolean
76
+ def salt=(salt)
77
+ unless salt.length == 16
78
+ raise StandardError, "Salt must be 16 bytes."
79
+ end
80
+
81
+ @options[:salt] = salt
82
+ end
83
+
84
+ # returns true if salt is defined.
85
+ # @return boolean
86
+ def salt?
87
+ unless @options.key?(:salt)
88
+ return false
89
+ end
90
+
91
+ true
92
+ end
93
+
94
+ # Encrypts a file with parameters set
95
+ # @see Core.encrypt!
96
+ def encrypt!
97
+ raise StandardError, "No entry file defined." unless file?
98
+ raise StandardError, "No output file defnined" unless output_file?
99
+ raise StandardError, "No salt defined" unless salt?
100
+
101
+ if Core.encrypt!(@options)
102
+ @options[:status] = true
103
+ else
104
+ @options[:status] = false
105
+ end
106
+ end
107
+
108
+ # Decrypts a file with parameters set
109
+ # @see Core.decrypt!
110
+ def decrypt!
111
+ raise StandardError, "No entry file defined." unless file?
112
+ raise StandardError, "No output file defnined" unless output_file?
113
+ raise StandardError, "No salt defined" unless salt?
114
+
115
+ if Core.decrypt!(@options)
116
+ @options[:status] = true
117
+ else
118
+ @options[:status] = false
119
+ end
120
+ end
121
+
122
+ # Returns the action status.
123
+ def status?
124
+ @options[:status]
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,3 @@
1
+ module Sekreti
2
+ VERSION = "0.1.0"
3
+ end
data/lib/sekreti.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "sekreti/version"
2
+ require "sekreti/crypt"
3
+
4
+ module Sekreti
5
+ class Error < StandardError; end
6
+ end
data/sekreti.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "sekreti/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sekreti"
7
+ spec.version = Sekreti::VERSION
8
+ spec.authors = ["atille"]
9
+ spec.email = ["gautierfrancois@outlook.com\n"]
10
+
11
+ spec.summary = %q{Easy-to-use encryption/decryption library}
12
+ spec.description = %q{Easy-to-use and configure encryption and decryption library based upon OpenSSL}
13
+ spec.homepage = "https://github.com/atilleh/sekreti"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/atilleh/sekreti"
20
+ spec.metadata["changelog_uri"] = "https://github.com/atilleh/sekreti/tree/master/changelog.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sekreti
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - atille
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-13 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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
+ description: Easy-to-use and configure encryption and decryption library based upon
56
+ OpenSSL
57
+ email:
58
+ - 'gautierfrancois@outlook.com
59
+
60
+ '
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - CODE_OF_CONDUCT.md
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - lib/sekreti.rb
76
+ - lib/sekreti/core.rb
77
+ - lib/sekreti/crypt.rb
78
+ - lib/sekreti/version.rb
79
+ - sekreti.gemspec
80
+ homepage: https://github.com/atilleh/sekreti
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ allowed_push_host: https://rubygems.org
85
+ homepage_uri: https://github.com/atilleh/sekreti
86
+ source_code_uri: https://github.com/atilleh/sekreti
87
+ changelog_uri: https://github.com/atilleh/sekreti/tree/master/changelog.md
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.0.4
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Easy-to-use encryption/decryption library
107
+ test_files: []