hide 0.1.1 → 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 +4 -4
- data/.codeclimate.yml +18 -0
- data/.gitignore +11 -0
- data/.reek +7 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +28 -0
- data/Appraisals +7 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +21 -0
- data/README.md +45 -0
- data/Rakefile +27 -0
- data/bin/hide +26 -22
- data/bin/reveal +27 -23
- data/gemfiles/openssl_2.0.0.gemfile +7 -0
- data/gemfiles/openssl_2.0.gemfile +7 -0
- data/hide.gemspec +35 -0
- data/lib/hide.rb +40 -25
- data/lib/hide/ae.rb +42 -26
- data/lib/hide/version.rb +4 -0
- metadata +132 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c114b2c4d2aa0fbb668676b860009259a4a5da33
|
|
4
|
+
data.tar.gz: fe92e211e2eac4bf4e472e2e1a612a7625aff399
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b548d2bc5764e73c70659cf72a4b4282f6f60a49bb584d0ee1d5fa083d8e4db094f295d467765677182faf57cd507b62b2f5c17f04f434371ee6a4aed1a34ec1
|
|
7
|
+
data.tar.gz: 72d2dfcc6c7ca1232b142a0a8cda94c1bd6bd3f0f0ad4836325f816a3aafdc1d1aff52bb5e1e0a6e49956a7bdc47d277377d7689fff609c5d2fa609a91e20a6b
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.reek
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.2
|
|
3
|
+
Style/StringLiterals:
|
|
4
|
+
EnforcedStyle: double_quotes
|
|
5
|
+
Style/UnneededCapitalW:
|
|
6
|
+
Enabled: false
|
|
7
|
+
Style/MethodDefParentheses:
|
|
8
|
+
Enabled: false
|
|
9
|
+
Metrics/MethodLength:
|
|
10
|
+
Max: 20
|
|
11
|
+
Metrics/AbcSize:
|
|
12
|
+
Enabled: false
|
|
13
|
+
Metrics/ParameterLists:
|
|
14
|
+
Max: 10
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
sudo: false
|
|
2
|
+
language: ruby
|
|
3
|
+
rvm:
|
|
4
|
+
- 2.3.4
|
|
5
|
+
- 2.4.1
|
|
6
|
+
- ruby-head
|
|
7
|
+
gemfile:
|
|
8
|
+
- gemfiles/openssl_2.0.0.gemfile
|
|
9
|
+
- gemfiles/openssl_2.0.gemfile
|
|
10
|
+
matrix:
|
|
11
|
+
allow_failures:
|
|
12
|
+
- rvm: ruby-head
|
|
13
|
+
fast_finish: true
|
|
14
|
+
cache: bundler
|
|
15
|
+
before_install: gem install bundler
|
|
16
|
+
addons:
|
|
17
|
+
code_climate:
|
|
18
|
+
repo_token: 1c1534b9452ce0fc942866617ff2949fa3ba9571838d92f0af44c5985bb0b582
|
|
19
|
+
after_success:
|
|
20
|
+
- bundle exec codeclimate-test-reporter
|
|
21
|
+
deploy:
|
|
22
|
+
provider: rubygems
|
|
23
|
+
api_key:
|
|
24
|
+
secure: IkCcu7MJC2izq1OQk1URxgfQsQBTnu2P1GN0MgYISnYIaBjUY2AHY7WfoOgfcO5pEoPxkcgCo5S1lLKZonmJZVhjHu77QxjJqAxIPwWAmR345GPaolZnxggID7Bi/HtNHhXPhwblfXfgvBgOoTBIYEAyf0RX+LhOmxmEYtI+IBNCbOyd9U0YWOgOJnGqzLHuJwNL59QvMZxoiULRgPuSVhmZDBqcZ/HGWL6zcqB3041CPK34PjHuTMKIzMJLD/n6PV6wGzyNfHsxUoBh6TiLCp+iqTN7v44lqIkmGLzQyEWuFWM9dgev8HEluZJpqwK7YKuQfWqcPZRR2Er2/6IMQ73LtS9Kyu5yoWuz1HO6a76s4rz98my7jl63Uy7NkAXxPs1Lez9sOjt3VtbZU7sysYX78g7pfeX5zSD1qrLuNXM3nMqo0LXu5QFaxerKxmeTnD4OxjZUqRDlUxXYFIJkdHOQoFVpkWUKxJ2F8X/SvPLAWscxoff+3f7MRTLql6mVHXh8/G/nqnib9Mc7rNE5fiTJmoDuEUBcnqSypc42bbyQT8xKNA5OK13to+MniTebb0cff/X3Gh+5XMT+cGQ9cOLQRlUUAFucaXx0+Fs87HkzhJTcpNToBw+dC7cOTFXLG5ztlnrsM3CutI47BMythpyc7y6U/s+LP5i65z/wOmE=
|
|
25
|
+
gem: hide
|
|
26
|
+
on:
|
|
27
|
+
tags: true
|
|
28
|
+
repo: at-shakil/hide
|
data/Appraisals
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-2017 Tahmid Shakil
|
|
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,45 @@
|
|
|
1
|
+
# Hide
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/at-shakil/hide)
|
|
4
|
+
[](https://badge.fury.io/rb/hide)
|
|
5
|
+
[](https://gemnasium.com/github.com/at-shakil/hide)
|
|
6
|
+
[](https://codeclimate.com/github/at-shakil/hide/coverage)
|
|
7
|
+
[](http://inch-ci.org/github/at-shakil/hide)
|
|
8
|
+
[](https://codeclimate.com/github/at-shakil/hide)
|
|
9
|
+
[](https://codeclimate.com/github/at-shakil/hide)
|
|
10
|
+
|
|
11
|
+
## Summary
|
|
12
|
+
|
|
13
|
+
Hide is a basic utility to encrypt/decrypt light-weight data files
|
|
14
|
+
with any extension.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Hide is a command-line utility. Installation can be performed using,
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
gem install hide
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Once installed, you can invoke encryption (`hide`) and decryption
|
|
27
|
+
(`reveal`) tools from anywhere.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
hide data_file.pdf
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
reveal data_file.pdf
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
It's that simple.
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
If you are interested in contributing, please [submit a pull request](https://help.github.com/articles/about-pull-requests/).
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
require "bundler/setup"
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
require "rdoc/task"
|
|
6
|
+
|
|
7
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
8
|
+
rdoc.main = "README.md"
|
|
9
|
+
rdoc.rdoc_dir = "rdoc"
|
|
10
|
+
rdoc.title = "Hide"
|
|
11
|
+
rdoc.markup = "markdown"
|
|
12
|
+
rdoc.options << "--line-numbers"
|
|
13
|
+
rdoc.rdoc_files.include("README.md")
|
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Rake::TestTask.new(:test) do |t|
|
|
18
|
+
t.libs << "test"
|
|
19
|
+
t.libs << "lib"
|
|
20
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
task :appraise do
|
|
24
|
+
exec "appraisal install && appraisal rake"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
task default: :test
|
data/bin/hide
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
require "bundler/setup"
|
|
3
|
+
require "hide"
|
|
4
|
+
require "io/console"
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
require 'io/console'
|
|
5
|
-
|
|
6
|
-
# TODO: Add verbosity module spanning from quite to highest verbosity settings
|
|
7
|
-
# TODO: Remove magic, implement settings
|
|
6
|
+
# Command-line interface base class for data file encryption
|
|
8
7
|
class CMDHide
|
|
9
8
|
def initialize file_name, salt = nil, iterator = nil
|
|
10
9
|
@file_name = file_name
|
|
11
|
-
file = open @file_name,
|
|
10
|
+
file = open @file_name, "rb"
|
|
12
11
|
@data = file.read
|
|
13
12
|
file.close
|
|
14
13
|
|
|
15
|
-
@salt =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
@salt =
|
|
15
|
+
if salt
|
|
16
|
+
salt
|
|
17
|
+
else
|
|
18
|
+
ENV["hide_salt"] ? ENV["hide_salt"] : "00000000"
|
|
19
|
+
end
|
|
20
|
+
@iter =
|
|
21
|
+
if iterator
|
|
22
|
+
iterator
|
|
23
|
+
else
|
|
24
|
+
ENV["hide_iterator"] ? ENV["hide_iterator"] : 30_000
|
|
25
|
+
end
|
|
21
26
|
end
|
|
22
27
|
|
|
23
28
|
def prompt
|
|
@@ -31,22 +36,21 @@ class CMDHide
|
|
|
31
36
|
|
|
32
37
|
def encrypt
|
|
33
38
|
encrypted = Hide::AE.encrypt @data, @password, @salt, @iter
|
|
34
|
-
file = open @file_name +
|
|
39
|
+
file = open @file_name + ".tmp", "wb"
|
|
35
40
|
file.write encrypted[:data] + encrypted[:iv] + encrypted[:auth_tag]
|
|
36
41
|
file.close
|
|
37
42
|
File.delete @file_name
|
|
38
|
-
File.rename @file_name +
|
|
43
|
+
File.rename @file_name + ".tmp", @file_name
|
|
39
44
|
end
|
|
40
45
|
|
|
41
46
|
def self.exec
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
47
|
+
raise(ArgumentError, "File name expected!") unless ARGV.any?
|
|
48
|
+
|
|
49
|
+
cmd_hide = CMDHide.new ARGV[0]
|
|
50
|
+
cmd_hide.prompt
|
|
51
|
+
cmd_hide.encrypt
|
|
52
|
+
rescue => e
|
|
53
|
+
puts e.message
|
|
50
54
|
end
|
|
51
55
|
end
|
|
52
56
|
|
data/bin/reveal
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
require "bundler/setup"
|
|
3
|
+
require "hide"
|
|
4
|
+
require "io/console"
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
require 'io/console'
|
|
5
|
-
|
|
6
|
-
# TODO: Add verbosity module spanning from quite to highest verbosity settings
|
|
7
|
-
# TODO: Remove magic, implement settings
|
|
6
|
+
# Command-line interface base class for data file decryption
|
|
8
7
|
class CMDReveal
|
|
9
8
|
def initialize file_name, salt = nil, iterator = nil
|
|
10
9
|
@file_name = file_name
|
|
11
|
-
file = open @file_name,
|
|
10
|
+
file = open @file_name, "rb"
|
|
12
11
|
data = file.read
|
|
13
12
|
file.close
|
|
14
|
-
@data = data[0..-(1 +
|
|
13
|
+
@data = data[0..-(1 + 12 + 16)] # iv_length + auth_tag_length
|
|
15
14
|
@iv = data[@data.length..-(1 + 16)] # auth_tag_length
|
|
16
15
|
@auth_tag = data[(@data.length + @iv.length)..-1]
|
|
17
16
|
|
|
18
|
-
@salt =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
@salt =
|
|
18
|
+
if salt
|
|
19
|
+
salt
|
|
20
|
+
else
|
|
21
|
+
ENV["hide_salt"] ? ENV["hide_salt"] : "00000000"
|
|
22
|
+
end
|
|
23
|
+
@iter =
|
|
24
|
+
if iterator
|
|
25
|
+
iterator
|
|
26
|
+
else
|
|
27
|
+
ENV["hide_iterator"] ? ENV["hide_iterator"] : 30_000
|
|
28
|
+
end
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
def prompt
|
|
@@ -34,22 +39,21 @@ class CMDReveal
|
|
|
34
39
|
|
|
35
40
|
def decrypt
|
|
36
41
|
decrypted = Hide::AE.decrypt @data, @password, @salt, @iter, @iv, @auth_tag
|
|
37
|
-
file = open @file_name +
|
|
42
|
+
file = open @file_name + ".tmp", "wb"
|
|
38
43
|
file.write decrypted
|
|
39
44
|
file.close
|
|
40
45
|
File.delete @file_name
|
|
41
|
-
File.rename @file_name +
|
|
46
|
+
File.rename @file_name + ".tmp", @file_name
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
def self.exec
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
end
|
|
50
|
+
raise(ArgumentError, "File name expected!") unless ARGV.any?
|
|
51
|
+
|
|
52
|
+
cmd_hide = CMDReveal.new ARGV[0]
|
|
53
|
+
cmd_hide.prompt
|
|
54
|
+
cmd_hide.decrypt
|
|
55
|
+
rescue => e
|
|
56
|
+
puts e.message
|
|
53
57
|
end
|
|
54
58
|
end
|
|
55
59
|
|
data/hide.gemspec
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "hide/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = "hide"
|
|
9
|
+
s.version = Hide::VERSION
|
|
10
|
+
s.summary = "A simple encryption utility"
|
|
11
|
+
s.description = "Hide is a basic utility to encrypt/decrypt
|
|
12
|
+
light-weight data files"
|
|
13
|
+
s.authors = ["Tahmid Shakil"]
|
|
14
|
+
s.email = ["at.shakil.92@gmail.com"]
|
|
15
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
|
16
|
+
s.bindir = "bin"
|
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
s.required_ruby_version = [">= 2.3.0"]
|
|
20
|
+
s.rdoc_options = %w[-t Hide -m README.md -N --markup markdown]
|
|
21
|
+
s.homepage = "https://github.com/at-shakil/hide"
|
|
22
|
+
s.license = "MIT"
|
|
23
|
+
|
|
24
|
+
s.add_dependency "openssl", "~> 2.0"
|
|
25
|
+
|
|
26
|
+
s.add_development_dependency "bundler", "~> 1.15"
|
|
27
|
+
s.add_development_dependency "rake", "~> 12.0"
|
|
28
|
+
s.add_development_dependency "minitest", "~> 5.0"
|
|
29
|
+
s.add_development_dependency "simplecov", "~> 0.13"
|
|
30
|
+
s.add_development_dependency "appraisal", "~> 2.2"
|
|
31
|
+
|
|
32
|
+
if ENV["TRAVIS"]
|
|
33
|
+
s.add_development_dependency "codeclimate-test-reporter", "~> 1.0.8"
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/hide.rb
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require "openssl"
|
|
2
|
+
require "securerandom"
|
|
3
|
+
require "hide/version"
|
|
4
|
+
require "hide/ae"
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
cipher.encrypt
|
|
10
|
-
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
|
|
11
|
-
cipher.iv = iv
|
|
12
|
-
{
|
|
13
|
-
data: cipher.update(data) + cipher.final,
|
|
14
|
-
iv: iv
|
|
15
|
-
}
|
|
16
|
-
end
|
|
6
|
+
# The primary module for `hide`
|
|
7
|
+
#
|
|
8
|
+
# Provides basic encryption/decryption support
|
|
9
|
+
module Hide
|
|
10
|
+
module_function
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
# Encrypts a data stream without any authentication identifier.
|
|
13
|
+
#
|
|
14
|
+
# For authenticated encryption support please use `Hide::AE` module
|
|
15
|
+
#
|
|
16
|
+
# Returns a hash containing encrypted data and IV
|
|
17
|
+
def encrypt(
|
|
18
|
+
data, key, salt, iter, iv = SecureRandom.random_bytes(16), key_length = 32
|
|
19
|
+
)
|
|
20
|
+
cipher = OpenSSL::Cipher.new "AES-256-CBC"
|
|
21
|
+
cipher.encrypt
|
|
22
|
+
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
|
|
23
|
+
cipher.iv = iv
|
|
24
|
+
{
|
|
25
|
+
data: cipher.update(data) + cipher.final,
|
|
26
|
+
iv: iv
|
|
27
|
+
}
|
|
26
28
|
end
|
|
27
|
-
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
# Decrypts any datastream with provided decryption credential
|
|
31
|
+
# and configuration.
|
|
32
|
+
#
|
|
33
|
+
# This method does not provide support for authenticated encryption.
|
|
34
|
+
# For authenticated encryption support, please use `Hide::AE` module
|
|
35
|
+
#
|
|
36
|
+
# Returns the decrypted data
|
|
37
|
+
def decrypt data, key, salt, iter, iv, key_length = 32
|
|
38
|
+
decipher = OpenSSL::Cipher.new "AES-256-CBC"
|
|
39
|
+
decipher.decrypt
|
|
40
|
+
decipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
|
|
41
|
+
decipher.iv = iv
|
|
42
|
+
decipher.update(data) + decipher.final
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/hide/ae.rb
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
module Hide
|
|
2
|
+
# `AE` implements authenticated encryption API based on AES-256
|
|
3
|
+
class AE
|
|
4
|
+
class << self
|
|
5
|
+
# Encrypts a data stream with an authenticity tag for reliable decryption
|
|
6
|
+
#
|
|
7
|
+
# Returns a hash containing encrypted data, IV and authentication tag
|
|
8
|
+
def encrypt(
|
|
9
|
+
data, key, salt, iter, iv = SecureRandom.random_bytes(12),
|
|
10
|
+
auth_data = "", key_length = 32
|
|
11
|
+
)
|
|
12
|
+
cipher = OpenSSL::Cipher.new "aes-256-gcm"
|
|
13
|
+
cipher.encrypt
|
|
14
|
+
cipher.key =
|
|
15
|
+
OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
|
|
16
|
+
cipher.iv = iv
|
|
17
|
+
cipher.auth_data = auth_data
|
|
18
|
+
{
|
|
19
|
+
data: cipher.update(data) + cipher.final,
|
|
20
|
+
iv: iv,
|
|
21
|
+
auth_tag: cipher.auth_tag
|
|
22
|
+
}
|
|
23
|
+
end
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.
|
|
25
|
+
# Decrypts an encrypted datastream with authenticity verification check
|
|
26
|
+
#
|
|
27
|
+
# [//]: # (TODO: investigate :reek:FeatureEnvy)
|
|
28
|
+
#
|
|
29
|
+
# Returns the decrypted data
|
|
30
|
+
def decrypt(
|
|
31
|
+
data, key, salt, iter, iv, auth_tag, auth_data = "", key_length = 32
|
|
32
|
+
)
|
|
33
|
+
decipher = OpenSSL::Cipher.new "aes-256-gcm"
|
|
34
|
+
decipher.decrypt
|
|
35
|
+
decipher.key =
|
|
36
|
+
OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
|
|
37
|
+
decipher.iv = iv
|
|
38
|
+
decipher.auth_tag = auth_tag
|
|
39
|
+
decipher.auth_data = auth_data
|
|
40
|
+
decipher.update(data) + decipher.final
|
|
41
|
+
rescue OpenSSL::Cipher::CipherError
|
|
42
|
+
raise ArgumentError, "Authentication failed"
|
|
43
|
+
end
|
|
28
44
|
end
|
|
29
45
|
end
|
|
30
46
|
end
|
data/lib/hide/version.rb
ADDED
metadata
CHANGED
|
@@ -1,40 +1,162 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hide
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tahmid Shakil
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: openssl
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :runtime
|
|
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: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.15'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.15'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '12.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '12.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: minitest
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '5.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '5.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: simplecov
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0.13'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0.13'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: appraisal
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '2.2'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '2.2'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: codeclimate-test-reporter
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 1.0.8
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 1.0.8
|
|
111
|
+
description: |-
|
|
112
|
+
Hide is a basic utility to encrypt/decrypt
|
|
113
|
+
light-weight data files
|
|
114
|
+
email:
|
|
115
|
+
- at.shakil.92@gmail.com
|
|
15
116
|
executables:
|
|
16
117
|
- hide
|
|
17
118
|
- reveal
|
|
18
119
|
extensions: []
|
|
19
120
|
extra_rdoc_files: []
|
|
20
121
|
files:
|
|
122
|
+
- ".codeclimate.yml"
|
|
123
|
+
- ".gitignore"
|
|
124
|
+
- ".reek"
|
|
125
|
+
- ".rubocop.yml"
|
|
126
|
+
- ".travis.yml"
|
|
127
|
+
- Appraisals
|
|
128
|
+
- Gemfile
|
|
129
|
+
- MIT-LICENSE
|
|
130
|
+
- README.md
|
|
131
|
+
- Rakefile
|
|
21
132
|
- bin/hide
|
|
22
133
|
- bin/reveal
|
|
134
|
+
- gemfiles/openssl_2.0.0.gemfile
|
|
135
|
+
- gemfiles/openssl_2.0.gemfile
|
|
136
|
+
- hide.gemspec
|
|
23
137
|
- lib/hide.rb
|
|
24
138
|
- lib/hide/ae.rb
|
|
25
|
-
|
|
139
|
+
- lib/hide/version.rb
|
|
140
|
+
homepage: https://github.com/at-shakil/hide
|
|
26
141
|
licenses:
|
|
27
|
-
-
|
|
142
|
+
- MIT
|
|
28
143
|
metadata: {}
|
|
29
144
|
post_install_message:
|
|
30
|
-
rdoc_options:
|
|
145
|
+
rdoc_options:
|
|
146
|
+
- "-t"
|
|
147
|
+
- Hide
|
|
148
|
+
- "-m"
|
|
149
|
+
- README.md
|
|
150
|
+
- "-N"
|
|
151
|
+
- "--markup"
|
|
152
|
+
- markdown
|
|
31
153
|
require_paths:
|
|
32
154
|
- lib
|
|
33
155
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
156
|
requirements:
|
|
35
157
|
- - ">="
|
|
36
158
|
- !ruby/object:Gem::Version
|
|
37
|
-
version:
|
|
159
|
+
version: 2.3.0
|
|
38
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
161
|
requirements:
|
|
40
162
|
- - ">="
|
|
@@ -42,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
42
164
|
version: '0'
|
|
43
165
|
requirements: []
|
|
44
166
|
rubyforge_project:
|
|
45
|
-
rubygems_version: 2.5
|
|
167
|
+
rubygems_version: 2.4.5
|
|
46
168
|
signing_key:
|
|
47
169
|
specification_version: 4
|
|
48
170
|
summary: A simple encryption utility
|