carrierwave_encrypter_decrypter 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 +15 -0
- data/lib/carrierwave/encrypter_decrypter/configuration.rb +15 -0
- data/lib/carrierwave/encrypter_decrypter/encryption.rb +12 -0
- data/lib/carrierwave/encrypter_decrypter/openssl/aes.rb +60 -0
- data/lib/carrierwave/encrypter_decrypter/uploader.rb +12 -0
- data/lib/carrierwave/encrypter_decrypter/version.rb +3 -0
- data/lib/carrierwave_encrypter_decrypter.rb +6 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjQzYjliMTkwZWJjYzYwMzQ4NTkxNzM3MjRlODMwZTUxZmYyMjUxNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjdhYTFjNTQ4MzdjMGNjYmZmMjk1OTVkMjVmODhlZWIzZDcxYTRiYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGE2ODY3NTM4MWE1OGU5NGMzMGIzZDFkZWU1NTMyY2FhYmJiOTFmMGRhZjk0
|
10
|
+
ZjU5Yjc1ZDI0NGZjY2RlNTMwODJiMWQwOTVlM2UxNWFiNWE4NWVjNWE1OWI5
|
11
|
+
YjJiNDYwYTI0ZDJmMjk2NDU5OGQ2NGYxZDQ5YzAwYzI0ZGRjMzE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGQyNmI2NmEyNTM1MGIwZTVkMjNmNjg0MjliNzVkNTU3MDhiYzUzZTUwMDYz
|
14
|
+
MDA5MDJmNWE2MmFlZTAzODllOThkNjJiZjlkMGJhMDY4MmIwNDg3Y2MxZWMz
|
15
|
+
MGMyYTVhODBlZDNiMmM0ODRkOTY2ODcxNDgwNjZkMjVmNzg0MTc=
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Carrierwave
|
2
|
+
module EncrypterDecrypter
|
3
|
+
def self.configure
|
4
|
+
yield configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Carrierwave::EncrypterDecrypter::Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :encryption_type, :key_size
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'carrierwave/encrypter_decrypter/openssl/aes'
|
2
|
+
|
3
|
+
class Encryption
|
4
|
+
def self.start!(obj)
|
5
|
+
encryption_type = Carrierwave::EncrypterDecrypter.configuration.encryption_type
|
6
|
+
|
7
|
+
case encryption_type
|
8
|
+
when :aes
|
9
|
+
Openssl::Aes.encrypt_for(obj)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Openssl
|
2
|
+
module Aes
|
3
|
+
def self.encrypt_for(obj)
|
4
|
+
begin
|
5
|
+
model = obj.model
|
6
|
+
mounted_as = obj.mounted_as
|
7
|
+
cipher = OpenSSL::Cipher.new("AES-#{Carrierwave::EncrypterDecrypter.configuration.key_size}-CBC")
|
8
|
+
cipher.encrypt
|
9
|
+
iv = cipher.random_iv
|
10
|
+
model.iv = iv
|
11
|
+
key = cipher.random_key
|
12
|
+
model.key = key
|
13
|
+
model.save!
|
14
|
+
|
15
|
+
original_file_path = File.expand_path(obj.store_path, obj.root)
|
16
|
+
encrypted_file_path = File.expand_path(obj.store_path, obj.root) + ".enc"
|
17
|
+
buf = ""
|
18
|
+
File.open(encrypted_file_path, "wb") do |outf|
|
19
|
+
File.open(model.send(mounted_as).path, "rb") do |inf|
|
20
|
+
while inf.read(4096, buf)
|
21
|
+
outf << cipher.update(buf)
|
22
|
+
end
|
23
|
+
outf << cipher.final
|
24
|
+
end
|
25
|
+
end
|
26
|
+
File.unlink(model.send(mounted_as).path)
|
27
|
+
rescue Exception => e
|
28
|
+
puts "****************************#{e.message}"
|
29
|
+
puts "****************************#{e.backtrace.inspect}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.decrypt_for(obj,opts)
|
34
|
+
begin
|
35
|
+
model = obj
|
36
|
+
mounted_as = opts[:mounted_as]
|
37
|
+
cipher = OpenSSL::Cipher.new("AES-#{Carrierwave::EncrypterDecrypter.configuration.key_size}-CBC")
|
38
|
+
cipher.decrypt
|
39
|
+
cipher.iv = model.iv
|
40
|
+
cipher.key = model.key
|
41
|
+
buf = ""
|
42
|
+
|
43
|
+
original_file_path = obj.send(mounted_as).root + obj.send(mounted_as).url
|
44
|
+
encrypted_file_path = obj.send(mounted_as).root + obj.send(mounted_as).url + ".enc"
|
45
|
+
|
46
|
+
File.open(original_file_path, "wb") do |outf|
|
47
|
+
File.open(encrypted_file_path, "rb") do |inf|
|
48
|
+
while inf.read(4096, buf)
|
49
|
+
outf << cipher.update(buf)
|
50
|
+
end
|
51
|
+
outf << cipher.final
|
52
|
+
end
|
53
|
+
end
|
54
|
+
rescue Exception => e
|
55
|
+
puts "****************************#{e.message}"
|
56
|
+
puts "****************************#{e.backtrace.inspect}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#Carrierwave::EncrypterDecrypter::Uploader.encrypt("ank")
|
2
|
+
require 'carrierwave/encrypter_decrypter/encryption.rb'
|
3
|
+
module Carrierwave
|
4
|
+
module EncrypterDecrypter
|
5
|
+
module Uploader
|
6
|
+
def self.encrypt(obj)
|
7
|
+
Encryption.start!(obj)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave_encrypter_decrypter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ankit gupta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: carrierwave
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A library supporting Ruby OpenSSL::Cipher and OpenSSL::PKCS5 for the
|
56
|
+
file encryption and decryption
|
57
|
+
email: ankit.gupta8898@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/carrierwave/encrypter_decrypter/encryption.rb
|
63
|
+
- lib/carrierwave/encrypter_decrypter/uploader.rb
|
64
|
+
- lib/carrierwave/encrypter_decrypter/configuration.rb
|
65
|
+
- lib/carrierwave/encrypter_decrypter/version.rb
|
66
|
+
- lib/carrierwave/encrypter_decrypter/openssl/aes.rb
|
67
|
+
- lib/carrierwave_encrypter_decrypter.rb
|
68
|
+
homepage: https://github.com/ankit8898/carrierwave_encrypter_decrypter
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.1.10
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Secure the files that you upload with carrierwave
|
92
|
+
test_files: []
|