encrypter_decrypter_files 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWYxMDc0NTA3NGUwYzU5YTJkNjBhMDQ4ODQ2MzIzNDA0ZTdmZWZjNQ==
5
+ data.tar.gz: !binary |-
6
+ ZTdlNmI5MjdkMjUxZTIyYzBmYzMxOWRkMTBlMjBhODE2MDc1ZGI2ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTk0ZmQ5ZjY2NjIzM2E0MGU1MzA0NzM0MGI1ZDYxNTBkZjNjY2EzZmE0NWVh
10
+ Yzk3ZjIxMmU3MzEwNzg4OGYzYTdkZTMyZDc4OWI1NzhjODMyYjcyMjhkMmRk
11
+ YTE1NGZiNjdkOTQwY2E4ZDc2ZjA2NjNjYjRmNDhhMmMzNTk4MDY=
12
+ data.tar.gz: !binary |-
13
+ ZGFjMGMzNjc3MDUxMDAyYzMxNWUyYWIyNTdhYjY3NGYxZDg1NGRmYjM2MzUx
14
+ NWUyMmMwOTUyYjVlZTYwYzljMzI2MmYzMTQzNjIzNTZmODY3YTE4ZGE3YTcy
15
+ NmQ0MzJmNDk2ODRlZDMxYjAxOGEzOWU4MDY2NGNmMDVjMjgwOWM=
@@ -0,0 +1,5 @@
1
+ class Base
2
+ def initialize(opts = {})
3
+ @path = opts[:path]
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ class EDfile < Base
2
+
3
+ def self.decrypt(opts = {})
4
+ obj = new(opts)
5
+ obj.trigger_decryption
6
+ end
7
+
8
+ def trigger_decryption
9
+
10
+ original_file_name = File.basename(@path.split('.enc').first)
11
+ data = YAML.load_file('iv_key.yml')
12
+ key = data[original_file_name][:key]
13
+ iv = data[original_file_name][:iv]
14
+
15
+ cipher = OpenSSL::Cipher.new('aes-256-cbc')
16
+ cipher.decrypt
17
+ cipher.key = key
18
+ cipher.iv = iv
19
+
20
+ buf = ""
21
+ original_file = @path.split('.enc').first
22
+ #encrypted_file = @path
23
+ File.open(original_file, "wb") do |outf|
24
+ File.open(@path, "rb") do |inf|
25
+ while inf.read(4096, buf)
26
+ outf << cipher.update(buf)
27
+ end
28
+ outf << cipher.final
29
+ end
30
+ end
31
+
32
+ ap 'Holla, Decrypted!'
33
+ end
34
+
35
+ end
36
+
37
+ # encryption
38
+
39
+
40
+ # # decryption
41
+ # cipher = OpenSSL::Cipher.new('aes-256-cbc')
42
+ # cipher.decrypt
43
+ # cipher.key = key
44
+ # cipher.iv = iv # key and iv are the ones from above
45
+
46
+ # buf = ""
47
+ # File.open("file.dec", "wb") do |outf|
48
+ # File.open("file.enc", "rb") do |inf|
49
+ # while inf.read(4096, buf)
50
+ # outf << cipher.update(buf)
51
+ # end
52
+ # outf << cipher.final
53
+ # end
54
+ # end
@@ -0,0 +1,31 @@
1
+ include Helper
2
+
3
+ class EDfile < Base
4
+
5
+ def self.encrypt(opts = {})
6
+ obj = new(opts)
7
+ obj.trigger_encryption
8
+ end
9
+
10
+ def trigger_encryption
11
+ cipher = OpenSSL::Cipher.new('aes-256-cbc')
12
+ cipher.encrypt
13
+ key = cipher.random_key
14
+ iv = cipher.random_iv
15
+
16
+ buf = ""
17
+ #original_file = File.basename(@path)
18
+ #encrypted_file = original_file + '.enc'
19
+ encrypted_file = @path + '.enc'
20
+ File.open(encrypted_file, "wb") do |outf|
21
+ File.open(@path, "rb") do |inf|
22
+ while inf.read(4096, buf)
23
+ outf << cipher.update(buf)
24
+ end
25
+ outf << cipher.final
26
+ end
27
+ end
28
+ write('iv_key.yml',{"#{File.basename(@path)}" => {iv: iv, key: key}})
29
+
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'openssl'
2
+ require 'yaml'
3
+ require 'awesome_print'
4
+ require 'helper'
5
+ require 'encrypter_decrypter/base.rb'
6
+ require 'encrypter_decrypter/decrypt.rb'
7
+ require 'encrypter_decrypter/encrypt.rb'
data/lib/helper.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+
3
+ module Helper
4
+ def write(filename, hash)
5
+ File.open(filename, "w+") do |f|
6
+ f.write(yaml(hash))
7
+ end
8
+ end
9
+
10
+ def yaml(hash)
11
+ method = hash.respond_to?(:ya2yaml) ? :ya2yaml : :to_yaml
12
+ string = hash.deep_stringify_keys.send(method)
13
+ string.gsub("!ruby/symbol ", ":").sub("---","").split("\n").map(&:rstrip).join("\n").strip
14
+ end
15
+
16
+ end
17
+
18
+ class Hash
19
+ def deep_stringify_keys
20
+ new_hash = {}
21
+ self.each do |key, value|
22
+ new_hash.merge!(key.to_s => (value.is_a?(Hash) ? value.deep_stringify_keys : value))
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encrypter_decrypter_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ankit gupta
8
+ - Ekta Verma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: awesome_print
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Encrypt Decrypt Any file using OpenSSL::AES
29
+ email:
30
+ - ankit.gupta8898@gmail.com
31
+ - eku4evr@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/encrypter_decrypter/decrypt.rb
37
+ - lib/encrypter_decrypter/encrypt.rb
38
+ - lib/encrypter_decrypter/base.rb
39
+ - lib/encrypter_decrypter_files.rb
40
+ - lib/helper.rb
41
+ homepage: https://github.com/gemathon-rockets/encrypter_decrypter_files
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.1.10
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Encrypt Decrypt Any file using OpenSSL::AES
65
+ test_files: []