hide 0.1.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 +7 -0
- data/bin/hide +53 -0
- data/bin/reveal +56 -0
- data/lib/hide.rb +29 -0
- data/lib/hide/ae.rb +30 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2135e98ed59928f37901050c264c32180ce14388
|
4
|
+
data.tar.gz: d7f399031f0b53ebe931618e6e2e0c2a56a6594f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc50135c39dc79bfceca7011a058e8a4e29c13497befe9f9831faf41c5d41f4656528fcc5e46b3c453b68f7b68b0c8fd46a52680d85d946e27e9692f1255b5fe
|
7
|
+
data.tar.gz: d5357d2568cc8ce9f09dcf3cc62fe79a9bb4d865634076dc92804e1f7a8285101d4815c53862de57b191047638a962aa64f97ff9e6b8a08f4918f90fabfaa6ef
|
data/bin/hide
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'hide'
|
4
|
+
require 'io/console'
|
5
|
+
|
6
|
+
# TODO: Add verbosity module spanning from quite to highest verbosity settings
|
7
|
+
# TODO: Remove magic, implement settings
|
8
|
+
class CMDHide
|
9
|
+
def initialize file_name, salt = nil, iterator = nil
|
10
|
+
@file_name = file_name
|
11
|
+
file = open @file_name, 'rb'
|
12
|
+
@data = file.read
|
13
|
+
file.close
|
14
|
+
|
15
|
+
@salt = salt ? salt : ENV["hide_salt"] ? ENV["hide_salt"] : '00000000'
|
16
|
+
@iter = if iterator
|
17
|
+
iterator
|
18
|
+
else
|
19
|
+
ENV["hide_iterator"] ? ENV["hide_iterator"] : 30000
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def prompt
|
24
|
+
puts "Password: "
|
25
|
+
while (pass = STDIN.noecho(&:gets)[0..-2]).empty?
|
26
|
+
puts "Err: Password can't be empty"
|
27
|
+
puts "Password: "
|
28
|
+
end
|
29
|
+
@password = pass
|
30
|
+
end
|
31
|
+
|
32
|
+
def encrypt
|
33
|
+
encrypted = Hide::AE.encrypt @data, @password, @salt, @iter
|
34
|
+
file = open @file_name + '.tmp', 'wb'
|
35
|
+
file.write encrypted[:data] + encrypted[:iv] + encrypted[:auth_tag]
|
36
|
+
file.close
|
37
|
+
File.delete @file_name
|
38
|
+
File.rename @file_name + '.tmp', @file_name
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.exec
|
42
|
+
begin
|
43
|
+
cmd_hide = CMDHide.new ARGV.any? ? ARGV[0] : raise(ArgumentError
|
44
|
+
.new('File name expected!'))
|
45
|
+
cmd_hide.prompt
|
46
|
+
cmd_hide.encrypt
|
47
|
+
rescue => e
|
48
|
+
puts e.message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
CMDHide.exec
|
data/bin/reveal
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'hide'
|
4
|
+
require 'io/console'
|
5
|
+
|
6
|
+
# TODO: Add verbosity module spanning from quite to highest verbosity settings
|
7
|
+
# TODO: Remove magic, implement settings
|
8
|
+
class CMDReveal
|
9
|
+
def initialize file_name, salt = nil, iterator = nil
|
10
|
+
@file_name = file_name
|
11
|
+
file = open @file_name, 'rb'
|
12
|
+
data = file.read
|
13
|
+
file.close
|
14
|
+
@data = data[0..-(1 + 16 + 16)] # iv_length + auth_tag_length
|
15
|
+
@iv = data[@data.length..-(1 + 16)] # auth_tag_length
|
16
|
+
@auth_tag = data[(@data.length + @iv.length)..-1]
|
17
|
+
|
18
|
+
@salt = salt ? salt : ENV["hide_salt"] ? ENV["hide_salt"] : '00000000'
|
19
|
+
@iter = if iterator
|
20
|
+
iterator
|
21
|
+
else
|
22
|
+
ENV["hide_iterator"] ? ENV["hide_iterator"] : 30000
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def prompt
|
27
|
+
puts "Password: "
|
28
|
+
while (pass = STDIN.noecho(&:gets)[0..-2]).empty?
|
29
|
+
puts "Err: Password can't be empty"
|
30
|
+
puts "Password: "
|
31
|
+
end
|
32
|
+
@password = pass
|
33
|
+
end
|
34
|
+
|
35
|
+
def decrypt
|
36
|
+
decrypted = Hide::AE.decrypt @data, @password, @salt, @iter, @iv, @auth_tag
|
37
|
+
file = open @file_name + '.tmp', 'wb'
|
38
|
+
file.write decrypted
|
39
|
+
file.close
|
40
|
+
File.delete @file_name
|
41
|
+
File.rename @file_name + '.tmp', @file_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.exec
|
45
|
+
begin
|
46
|
+
cmd_hide = CMDReveal.new ARGV.any? ? ARGV[0] : raise(ArgumentError
|
47
|
+
.new('File name expected!'))
|
48
|
+
cmd_hide.prompt
|
49
|
+
cmd_hide.decrypt
|
50
|
+
rescue => e
|
51
|
+
puts e.message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
CMDReveal.exec
|
data/lib/hide.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
class Hide
|
5
|
+
class << self
|
6
|
+
def encrypt data, key, salt, iter, iv=SecureRandom.random_bytes(16),
|
7
|
+
key_length = 32
|
8
|
+
cipher = OpenSSL::Cipher.new 'AES-256-CBC'
|
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
|
17
|
+
|
18
|
+
def decrypt data, key, salt, iter, iv, key_length
|
19
|
+
decipher = OpenSSL::Cipher.new 'AES-256-CBC'
|
20
|
+
decipher.decrypt
|
21
|
+
decipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter,
|
22
|
+
key_length)
|
23
|
+
decipher.iv = iv
|
24
|
+
decipher.update(data) + decipher.final
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'hide/ae'
|
data/lib/hide/ae.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Hide::AE
|
2
|
+
class << self
|
3
|
+
def encrypt data, key, salt, iter, iv = SecureRandom.random_bytes(16),
|
4
|
+
auth_data = String.new, key_length = 32
|
5
|
+
cipher = OpenSSL::Cipher.new 'aes-256-gcm'
|
6
|
+
cipher.encrypt
|
7
|
+
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
|
8
|
+
cipher.iv = iv
|
9
|
+
cipher.auth_data = auth_data
|
10
|
+
{
|
11
|
+
data: cipher.update(data) + cipher.final,
|
12
|
+
iv: iv,
|
13
|
+
auth_tag: cipher.auth_tag
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def decrypt data, key, salt, iter, iv, auth_tag, auth_data = String.new,
|
18
|
+
key_length = 32
|
19
|
+
decipher = OpenSSL::Cipher.new 'aes-256-gcm'
|
20
|
+
decipher.decrypt
|
21
|
+
decipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter,
|
22
|
+
key_length)
|
23
|
+
decipher.iv = iv
|
24
|
+
decipher.auth_tag = auth_tag
|
25
|
+
decipher.auth_data = auth_data
|
26
|
+
decipher.update(data) + decipher.final rescue raise ArgumentError
|
27
|
+
.new('Authentication failed')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tahmid Shakil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Hide is a basic utility to encrypt/decrypt light-weight data files
|
14
|
+
email: at.shakil.92@gmail.com
|
15
|
+
executables:
|
16
|
+
- hide
|
17
|
+
- reveal
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/hide
|
22
|
+
- bin/reveal
|
23
|
+
- lib/hide.rb
|
24
|
+
- lib/hide/ae.rb
|
25
|
+
homepage: https://github.com/atshakil/hide
|
26
|
+
licenses:
|
27
|
+
- CC-BY-SA-4.0
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.5.1
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: A simple encryption utility
|
49
|
+
test_files: []
|