encryption 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +12 -7
- data/encryption.gemspec +1 -1
- data/lib/helpers/string.rb +1 -0
- data/lib/modules/symmetric.rb +10 -19
- data/spec/helpers/string_spec.rb +20 -0
- metadata +7 -5
- checksums.yaml +0 -15
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,7 +83,7 @@ private_key.to_pem('passphrase')
|
|
83
83
|
|
84
84
|
`Encryption::PublicKey` and `Encryption::PrivateKey`
|
85
85
|
----------------------------------------------------
|
86
|
-
Both classes have the same
|
86
|
+
Both classes have the same methods
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
# Import an existing key
|
@@ -92,13 +92,12 @@ Encryption::PublicKey.new(string[, password]) # From string
|
|
92
92
|
|
93
93
|
# Encrypt / Decrypt data
|
94
94
|
public_key = Encryption::PublicKey.new("existing key")
|
95
|
-
public_key.encrypt("
|
96
|
-
public_key.
|
95
|
+
public_key.encrypt("2001: A Space Odyssey")
|
96
|
+
public_key.decrypt("H3LL0¡")
|
97
97
|
|
98
98
|
# Note that you can use both public and private keys to encrypt and decrypt data
|
99
99
|
```
|
100
100
|
|
101
|
-
|
102
101
|
Helpers
|
103
102
|
-------
|
104
103
|
String helper
|
@@ -113,13 +112,19 @@ Helpers
|
|
113
112
|
"h3LL0".decrypt!
|
114
113
|
|
115
114
|
# With custom settings (and custom encryptor instance)
|
116
|
-
"
|
115
|
+
"Contact".encrypt({ key: 'encryption key', iv: 'initialization vector', cipher: 'encryption algorithm' })
|
116
|
+
|
117
|
+
# Or with a custom encryptor
|
118
|
+
encryptor = Encryption::Symmetric.new
|
119
|
+
encryptor.key = 'random string'
|
120
|
+
"Interstate 60".encrypt(encryptor: encryptor)
|
117
121
|
```
|
118
122
|
|
119
123
|
License
|
120
124
|
-------
|
121
|
-
This gem is distributed under
|
125
|
+
This gem is distributed under The MIT License.
|
122
126
|
|
123
127
|
Author
|
124
128
|
------
|
125
|
-
Itay Grudev
|
129
|
+
Itay Grudev
|
130
|
+
![Itay Grudev](http://safemail.justlikeed.net/e/a5307c0c2dd405f756cab9f4c76cd63a.png)
|
data/encryption.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'date'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'encryption'
|
5
|
-
s.version = '1.1.
|
5
|
+
s.version = '1.1.3'
|
6
6
|
s.date = Date.today.to_s
|
7
7
|
s.summary = 'A simple wrapper for the OpenSSL Cipher library'
|
8
8
|
s.description = 'Encryption provides a simple interface for symmetric / asymmetric encryption with the OpenSSL Cipher library'
|
data/lib/helpers/string.rb
CHANGED
data/lib/modules/symmetric.rb
CHANGED
@@ -20,35 +20,26 @@ module Encryption
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def encrypt(data)
|
23
|
-
cipher_init
|
23
|
+
cipher_init(:cipher, :encrypt)
|
24
24
|
@cipher.update(data) + @cipher.final
|
25
25
|
end
|
26
26
|
|
27
27
|
def decrypt(data)
|
28
|
-
|
28
|
+
cipher_init(:decipher, :decrypt)
|
29
29
|
@decipher.update(data) + @decipher.final
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
-
|
34
|
-
def cipher_init
|
35
|
-
if @cipher.nil?
|
36
|
-
@cipher = OpenSSL::Cipher.new(@configuration.cipher)
|
37
|
-
@cipher.encrypt
|
38
|
-
end
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if @decipher.nil?
|
46
|
-
@decipher = OpenSSL::Cipher.new(@configuration.cipher)
|
47
|
-
@decipher.decrypt
|
34
|
+
def cipher_init(name, mode)
|
35
|
+
obj = instance_variable_get((name = '@' + name.to_s))
|
36
|
+
if obj.nil?
|
37
|
+
obj = instance_variable_set(name, OpenSSL::Cipher.new(@configuration.cipher))
|
38
|
+
obj.send mode
|
48
39
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
40
|
+
|
41
|
+
obj.key = @configuration.key
|
42
|
+
obj.iv = @configuration.iv
|
52
43
|
end
|
53
44
|
|
54
45
|
end
|
data/spec/helpers/string_spec.rb
CHANGED
@@ -40,4 +40,24 @@ describe String do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe "with custom encryptor" do
|
44
|
+
before(:each) do
|
45
|
+
@string = String.random
|
46
|
+
encryptor = Encryption::Symmetric.new
|
47
|
+
encryptor.key = String.random
|
48
|
+
encryptor.iv = String.random
|
49
|
+
@options = {
|
50
|
+
encryptor: encryptor
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should generate encryption different then the original string' do
|
55
|
+
@string.encrypt(@options).should_not == @string
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should decrypt, encrypted values and match the original string' do
|
59
|
+
@string.encrypt(@options).decrypt(@options).should == @string
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
43
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encryption
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Itay Grudev
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
14
|
description: Encryption provides a simple interface for symmetric / asymmetric encryption
|
14
15
|
with the OpenSSL Cipher library
|
@@ -53,25 +54,26 @@ files:
|
|
53
54
|
homepage: https://github.com/Itehnological/encryption
|
54
55
|
licenses:
|
55
56
|
- MIT
|
56
|
-
metadata: {}
|
57
57
|
post_install_message:
|
58
58
|
rdoc_options: []
|
59
59
|
require_paths:
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
62
63
|
requirements:
|
63
64
|
- - ! '>='
|
64
65
|
- !ruby/object:Gem::Version
|
65
66
|
version: '0'
|
66
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
67
69
|
requirements:
|
68
70
|
- - ! '>='
|
69
71
|
- !ruby/object:Gem::Version
|
70
72
|
version: '0'
|
71
73
|
requirements: []
|
72
74
|
rubyforge_project:
|
73
|
-
rubygems_version:
|
75
|
+
rubygems_version: 1.8.25
|
74
76
|
signing_key:
|
75
|
-
specification_version:
|
77
|
+
specification_version: 3
|
76
78
|
summary: A simple wrapper for the OpenSSL Cipher library
|
77
79
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
YTBkNmY0MjNlNGVlZjI2NzNlOGM3NDBjM2UxYzlmYTJiMDI0MTcxYQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MGY0ZjExNjA3NGI2Yzk1ZGQ0NzM5YmQyZDM4ZmUxMDNjMmQwODYzMA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
OWEyYWE2NzU0ZWQ2YmZkZmJhMmY4Yjc3ZGFlZWZiZTlhYTAxNDcwODQ5OTMx
|
10
|
-
Mjg1YjE5Njg2MmE2NWE0NmQ4NjExYWQ0MWQ0ZTY1ZTQ3NTM0ODZkNTZjOWVm
|
11
|
-
MmFmYzJhMGExOGYyMWJhMWFlODAzYzE5OWQ0ZDA3ZDExMDZkMjc=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZDY1MjhkMTk1YWQ4YzQ1OTY3OTI5YTdiZmU5NTRmODE0MGVjZDQ3YWMyZTk5
|
14
|
-
ZjdhZjAxYzFhYThmN2I4Njc4ODliN2U3YzRmMGM5YTljYzk4Yzk3MDUyZDBi
|
15
|
-
NDY2ZGQ4ZmZmYzIwOGM2MGQ1MzBkOWNiNGNmMmY1N2E3YTEzOTk=
|