sekreti 0.1.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 108dc200e277cc9f254211e0d92c30783ab5f8a721da05865519c45f2a641022
4
- data.tar.gz: 7ab731092115d74199651c9cd2abf3068852f457a52034cc18cd20157947c996
3
+ metadata.gz: b1d51efb62be86810b62a97753d3be7a475c2bbe2e729eb84cb88638f6d56fb7
4
+ data.tar.gz: 8821f5364226ed49628cf4a7283c8e35d61be2a69fb471effddc4248762e1367
5
5
  SHA512:
6
- metadata.gz: 90f91b9dccca63e2e3624eca0b9ed4db17af7564b87cf596fd50118e33b90ae90b016d455e0e7fc5f39f52d014a70d3ebb7fcb056505a4ed4078f6e4e8b2f454
7
- data.tar.gz: 2ede38a4586530a9ac6d4e27241f7d52cbd3e2e17a872425dea65e0284f0fad6f982866daadb882e3ff1e1f7d0770d2dcf153609f53f588c1fddf538d4cffd59
6
+ metadata.gz: c0a5cbc6fc2b87101d66b251af285bd879dbc1d375858973b68cfc3c447437d49bcac9e50a8430dbb803cf9c523f485e391b33da4cd41d1bf3e2eab98be2308b
7
+ data.tar.gz: 5a10038e3e8d038414b93196937508fa12d019ac5307372484d401d1c4234c41d3c598cc17e977bed8565c0a21fbd47f44c6cd5e5ec7554e01efc590ce661e0e
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in sekret.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'yard'
8
+ gem 'redcarpet'
9
+ end
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
1
  # sekreti
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/sekreti.svg)](https://badge.fury.io/rb/sekreti)
4
+
3
5
  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
6
  \
5
- At the moment, sekreti only supports AES-128-CBC encryption protocol, but some other could be added in the future.
7
+ Sekreti currently supports `AES-128-CBC` and `AES-256-CBC` protocol.
6
8
 
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'sekreti'
14
+ gem 'sekreti', '1.0.0'
13
15
  ```
14
16
 
15
17
  And then execute:
@@ -29,22 +31,28 @@ From a Ruby file, basic steps are :
29
31
  ```ruby
30
32
  require "sekreti"
31
33
 
32
- # Encrypt a file
33
34
  encrypt = sekreti::Crypt.new
34
35
  encrypt.file = "./decrypted_file.txt"
35
36
  encrypt.output_file = "./encrypted_output.txt"
36
- encrypt.salt = "aaaaaaaaaaaaaaaa" # a 16 bytes long encryption key
37
+ encrypt.protocol = "AES-256-CBC" # is aes-128-cbc by default
38
+
39
+ # You must define an encryption key.
40
+ # Is 16 bytes long for aes-128-cbc
41
+ # Is 32 bytes long for aes-256-cbc
42
+ encrypt.key = "a" * 32 # a 16 bytes long encryption key for aes-128-cbc
37
43
 
38
44
  # Validate that everything is ok
39
45
 
40
46
  encrypt.file? # true
41
47
  encrypt.output_file? # true
42
- encrypt.salt? # true
48
+ encrypt.key? # true
49
+
43
50
 
44
51
  # Encrypt the file
45
52
  encrypt.status? # false
46
53
  encrypt.encrypt! # returns true
47
54
  encrypt.status? # true
55
+ encrypt.dump # Returns the whole state
48
56
  ```
49
57
 
50
58
  ### Decrypt a file
@@ -54,18 +62,21 @@ require "sekreti"
54
62
  decrypt = sekreti::Crypt.new
55
63
  decrypt.file = "./encrypted_file.txt"
56
64
  decrypt.output_file = "./decrypted_output.txt"
57
- decrypt.salt = "aaaaaaaaaaaaaaaa" # a 16 bytes long decryption key
65
+ decrypt.key = "a" * 32
58
66
 
59
67
  # Validate that everything is ok
60
68
 
61
69
  decrypt.file? # true
62
70
  decrypt.output_file? # true
63
- decrypt.salt? # true
71
+ decrypt.key? # true
64
72
 
65
73
  # Decrypt the file
66
74
  decrypt.status? # false
67
75
  decrypt.decrypt! # returns true
68
76
  decrypt.status? # true
77
+
78
+ # Dump the whole state
79
+ decrypt.dump
69
80
  ```
70
81
 
71
82
  ## Development
@@ -74,9 +85,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
74
85
 
75
86
  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
87
 
88
+ The documentation can be generated with `Yard` :
89
+ ```bash
90
+ bundle exec rake doc
91
+ ```
92
+
77
93
  ## Contributing
78
94
 
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.
95
+ Bug reports and pull requests are welcome on GitHub at https://github.com/atilleh/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
96
 
81
97
  ## License
82
98
 
@@ -84,4 +100,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
84
100
 
85
101
  ## Code of Conduct
86
102
 
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).
103
+ 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/atilleh/sekreti/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -10,12 +10,12 @@ namespace :sekreti do
10
10
  desc "Encrypt a file using sekreti gem"
11
11
  task :encrypt do
12
12
  sekreti = sekreti::Crypt.new
13
- sekreti.file = ENV["sekreti_FILE"]
13
+ sekreti.file = ENV["SEKRETI_FILE"]
14
14
  sekreti.output_file = ENV["sekreti_OUTPUT"]
15
- unless ENV["sekreti_KEY"]
15
+ unless ENV["SEKRETI_KEY"]
16
16
  sekreti.salt = SecureRandom.hex(32)[0..15]
17
17
  else
18
- sekreti.salt = ENV["sekreti_KEY"]
18
+ sekreti.salt = ENV["SEKRETI_KEY"]
19
19
  end
20
20
 
21
21
  if sekreti.encrypt!
@@ -26,11 +26,16 @@ namespace :sekreti do
26
26
  desc "Decrypt a file using sekreti gem"
27
27
  task :decrypt do
28
28
  sekreti = sekreti::Crypt.new
29
- sekreti.file = ENV["sekreti_FILE"]
30
- sekreti.outpuf_file = ENV["sekreti_OUTPUT"]
31
- sekreti.salt = ENV["sekreti_KEY"]
29
+ sekreti.file = ENV["SEKRETI_FILE"]
30
+ sekreti.outpuf_file = ENV["SEKRETI_OUTPUT"]
31
+ sekreti.salt = ENV["SEKRETI_KEY"]
32
32
  if sekreti.decrypt!
33
33
  puts "File decrypted."
34
34
  end
35
35
  end
36
+ end
37
+
38
+ desc "Generates documentation with Yard"
39
+ task :doc do
40
+ sh "bundle exec yardoc"
36
41
  end
data/lib/sekreti.rb CHANGED
@@ -3,4 +3,4 @@ require "sekreti/crypt"
3
3
 
4
4
  module Sekreti
5
5
  class Error < StandardError; end
6
- end
6
+ end
data/lib/sekreti/core.rb CHANGED
@@ -2,39 +2,49 @@ require "openssl"
2
2
  module Sekreti
3
3
  # Main class performing operations.
4
4
  class Core
5
+
6
+ protected
5
7
  # Encrypts a file with AES-128-CBC cipher, using
6
8
  # a submitted 16 bytes string.
7
9
  # @param options [Hash] submitted parameters
8
10
  # @return boolean
9
11
  def self.encrypt!(options)
10
- cipher = OpenSSL::Cipher.new("AES-128-CBC")
11
- cipher.encrypt
12
- cipher.key = options[:salt]
12
+ begin
13
+ cipher = OpenSSL::Cipher.new(options[:protocol])
14
+ cipher.encrypt
15
+ cipher.key = options[:key]
13
16
 
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)
17
+ f = File.open(
18
+ options[:output_file],
19
+ 'wb'
20
+ )
21
+
22
+ encrypted = cipher.update(File.read(options[:path])) + cipher.final
23
+ f.write(encrypted)
21
24
 
22
- return true
25
+ return true
26
+ rescue
27
+ return false
28
+ end
23
29
  end
24
30
 
25
31
  # Decrypts a file with a submitted key.
26
32
  # @param options [Hash] submitted parameters
27
33
  # @return boolean
28
34
  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)
35
+ begin
36
+ decipher = OpenSSL::Cipher.new(options[:protocol])
37
+ decipher.decrypt
38
+ decipher.key = options[:key]
39
+
40
+ f = File.open(options[:output_file], 'w')
41
+ decrypted = decipher.update(File.read(options[:path])) + decipher.final
42
+ f.write(decrypted)
36
43
 
37
- return true
44
+ return true
45
+ rescue
46
+ return false
47
+ end
38
48
  end
39
49
  end
40
50
  end
data/lib/sekreti/crypt.rb CHANGED
@@ -4,8 +4,31 @@ module Sekreti
4
4
  # Access helper to call the encryption and decryption
5
5
  # actions.
6
6
  class Crypt
7
- def initialize(options={})
8
- @options = options
7
+ def initialize()
8
+ @options = {
9
+ path: nil,
10
+ output_file: nil,
11
+ protocol: "AES-128-CBC",
12
+ status: false
13
+ }
14
+ end
15
+
16
+ # Returns encryption protocol
17
+ # @return encryption protocol
18
+ def protocol
19
+ @options[:protocol]
20
+ end
21
+
22
+ def protocol?
23
+ unless @options.key?(:protocol)
24
+ return false
25
+ end
26
+
27
+ true
28
+ end
29
+
30
+ def protocol=(protocol)
31
+ @options[:protocol] = protocol
9
32
  end
10
33
 
11
34
  # Returns entry file
@@ -64,27 +87,31 @@ module Sekreti
64
87
  true
65
88
  end
66
89
 
67
- # Returns the encryption salt
68
- # @return encryption salt
69
- def salt
70
- @options[:salt]
90
+ # Returns the encryption key
91
+ # @return encryption key
92
+ def key
93
+ @options[:key]
71
94
  end
72
95
 
73
- # Set the encryption salt
74
- # @param salt [String] 16 bytes string
96
+ # Set the encryption key
97
+ # @param key [String] 16 bytes string
75
98
  # @return boolean
76
- def salt=(salt)
77
- unless salt.length == 16
78
- raise StandardError, "Salt must be 16 bytes."
99
+ def key=(key)
100
+ if @options[:protocol] == "AES-128-CBC"
101
+ raise(StandardError, "Key must be 16 bytes long.") if key.length != 16
79
102
  end
80
103
 
81
- @options[:salt] = salt
104
+ if @options[:protocol] == "AES-256-CBC"
105
+ raise(StandardError, "Key must be 32 bytes long.") if key.length != 32
106
+ end
107
+
108
+ @options[:key] = key
82
109
  end
83
110
 
84
- # returns true if salt is defined.
111
+ # returns true if key is defined.
85
112
  # @return boolean
86
- def salt?
87
- unless @options.key?(:salt)
113
+ def key?
114
+ unless @options.key?(:key)
88
115
  return false
89
116
  end
90
117
 
@@ -96,7 +123,7 @@ module Sekreti
96
123
  def encrypt!
97
124
  raise StandardError, "No entry file defined." unless file?
98
125
  raise StandardError, "No output file defnined" unless output_file?
99
- raise StandardError, "No salt defined" unless salt?
126
+ raise StandardError, "No key defined" unless key?
100
127
 
101
128
  if Core.encrypt!(@options)
102
129
  @options[:status] = true
@@ -110,7 +137,7 @@ module Sekreti
110
137
  def decrypt!
111
138
  raise StandardError, "No entry file defined." unless file?
112
139
  raise StandardError, "No output file defnined" unless output_file?
113
- raise StandardError, "No salt defined" unless salt?
140
+ raise StandardError, "No key defined" unless key?
114
141
 
115
142
  if Core.decrypt!(@options)
116
143
  @options[:status] = true
@@ -123,5 +150,11 @@ module Sekreti
123
150
  def status?
124
151
  @options[:status]
125
152
  end
153
+
154
+ # Returns the configuration
155
+ # @return current instance configuration.
156
+ def dump
157
+ @options
158
+ end
126
159
  end
127
160
  end
@@ -1,3 +1,3 @@
1
1
  module Sekreti
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/sekreti.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["atille"]
9
9
  spec.email = ["gautierfrancois@outlook.com\n"]
10
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}
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. Currently supports AES-128-CBC and AES-256-CBC encryption protocol.}
13
13
  spec.homepage = "https://github.com/atilleh/sekreti"
14
14
  spec.license = "MIT"
15
15
 
@@ -31,4 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "bundler", "~> 2.0"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "yard"
35
+ spec.add_development_dependency "redcarpet"
34
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sekreti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - atille
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-13 00:00:00.000000000 Z
11
+ date: 2019-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,36 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.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: redcarpet
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'
55
83
  description: Easy-to-use and configure encryption and decryption library based upon
56
- OpenSSL
84
+ OpenSSL. Currently supports AES-128-CBC and AES-256-CBC encryption protocol.
57
85
  email:
58
86
  - 'gautierfrancois@outlook.com
59
87
 
@@ -103,5 +131,5 @@ requirements: []
103
131
  rubygems_version: 3.0.4
104
132
  signing_key:
105
133
  specification_version: 4
106
- summary: Easy-to-use encryption/decryption library
134
+ summary: Easy-to-use encryption/decryption library.
107
135
  test_files: []