encryptedzip 0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +1 -0
- data/encryptedzip.gemspec +25 -0
- data/lib/encryptedzip.rb +67 -0
- data/lib/encryptedzip/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0aa40b41e695d1cef7386eaa39b51342440b4ec7
|
4
|
+
data.tar.gz: ee0de528ffdd5fbbf1910be3a13a6ce83dbced73
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9968c58692142c2502343173fdfcca70153686b887d727a040187771ff8bd4f5dad5129a6d10c99652d51ffa545813f016a6b47ba0db49e7a62c3f49f75e58c3
|
7
|
+
data.tar.gz: c74c9a7e84f156c61d60259c34600c6033013d2bc0f5f4db5c86ee31395af508ee2f3229783564bfb2233eeacf209d1f2e5591f6ba55a8de4709c142db581da5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Nipper
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# EncryptedZip
|
2
|
+
|
3
|
+
Use EncryptedZip to create an archive of encrypted files. Files are encrypted using AES-256 using a randomly generated base64 password of approximately 100 characteres. The password is encrypted according to a provided public key. The encrypted password is then stored as a txt file and zipped along with the encrypted zip.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'encryptedzip'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install encryptedzip
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You must specify a public key file to use for the password encryption:
|
22
|
+
```
|
23
|
+
EncryptedZip.public_key_file = 'public.pem'
|
24
|
+
```
|
25
|
+
|
26
|
+
You can then create an encrypted zip file by providing an output filepath and an array of filepaths to encrypt.
|
27
|
+
```
|
28
|
+
EncryptedZip.create_encrypted_zip(output_filepath: 'archive.zip', files: ['secret.txt'])
|
29
|
+
```
|
30
|
+
|
31
|
+
Optionally, you can provide a password_path and encrypted_filepath.
|
32
|
+
```
|
33
|
+
EncryptedZip.password_path = "p4$$w0rd.txt"
|
34
|
+
EncryptedZip.encrypted_filepath = "BigSecret.zip"
|
35
|
+
```
|
36
|
+
|
37
|
+
To generate a 4096-bit private key:
|
38
|
+
`$ openssl genrsa -des3 -out private.pem 4096`
|
39
|
+
|
40
|
+
To generate a public key from a private key:
|
41
|
+
`$ openssl rsa -in private.pem -out public.pem -outform PEM -pubout`
|
42
|
+
|
43
|
+
Example script to decrypt a password file:
|
44
|
+
|
45
|
+
```
|
46
|
+
require 'openssl'
|
47
|
+
|
48
|
+
private_key_file = 'private.pem'
|
49
|
+
password = '' # password used during key genertation
|
50
|
+
encrypted_string = File.read('password.txt')
|
51
|
+
private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file),password)
|
52
|
+
puts private_key.private_decrypt(encrypted_string)
|
53
|
+
```
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'encryptedzip/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "encryptedzip"
|
8
|
+
spec.version = EncryptedZip::VERSION
|
9
|
+
spec.authors = ["Michael Nipper"]
|
10
|
+
spec.email = ["mjn4406@gmail.com"]
|
11
|
+
spec.description = %q{Created an encrypted zip.}
|
12
|
+
spec.summary = %q{Create an encrypted zip file. The encrypted zip is then zipped with an encrypted password.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "zipruby", "~> 0.3"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/encryptedzip.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative './encryptedzip/version'
|
2
|
+
require 'openssl'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'zipruby'
|
5
|
+
|
6
|
+
module EncryptedZip
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :public_key_file, :encrypted_filepath, :password_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create_encrypted_zip(options={})
|
13
|
+
check_errors(options)
|
14
|
+
password = generate_password
|
15
|
+
create_password_file(password)
|
16
|
+
|
17
|
+
create_zip(encrypted_filepath, options[:files])
|
18
|
+
Zip::Archive.encrypt(encrypted_filepath, password)
|
19
|
+
|
20
|
+
create_zip(options[:output_filepath],
|
21
|
+
[password_path, encrypted_filepath])
|
22
|
+
|
23
|
+
clean_up
|
24
|
+
options[:output_filepath]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def self.encrypted_filepath
|
29
|
+
@encrypted_filepath || 'encrypted.zip'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.password_path
|
33
|
+
@password_path || 'password.txt'
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.create_zip(filename, files)
|
37
|
+
Zip::Archive.open(filename, Zip::CREATE) do |archive|
|
38
|
+
files.each do |file|
|
39
|
+
archive.add_file(file)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.clean_up
|
45
|
+
File.delete(encrypted_filepath, password_path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.generate_password
|
49
|
+
SecureRandom.base64(85)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.encrypt_string(string)
|
53
|
+
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
|
54
|
+
cipher = public_key.public_encrypt(string)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.create_password_file(password)
|
58
|
+
File.open(password_path, "wb") {|f| f.write(encrypt_string password)}
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.check_errors(options)
|
62
|
+
raise "You must set a public key file location" unless @public_key_file
|
63
|
+
raise "Place a public key at #{@public_key_file}" unless File.exists? @public_key_file
|
64
|
+
raise "You must supply an output filepath" unless options.has_key? :output_filepath
|
65
|
+
raise "You must supply a list of files to encrypt" unless options.has_key? :files
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: encryptedzip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Nipper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zipruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.3'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Created an encrypted zip.
|
56
|
+
email:
|
57
|
+
- mjn4406@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- encryptedzip.gemspec
|
68
|
+
- lib/encryptedzip.rb
|
69
|
+
- lib/encryptedzip/version.rb
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Create an encrypted zip file. The encrypted zip is then zipped with an encrypted
|
94
|
+
password.
|
95
|
+
test_files: []
|