shuber-encryptor 1.0.0 → 1.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.
- data/CHANGELOG +3 -0
- data/README.markdown +51 -3
- data/lib/encryptor.rb +6 -5
- data/test/encryptor_test.rb +6 -6
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -18,13 +18,61 @@ Usage
|
|
18
18
|
decrypted_value = Huberry::Encryptor.decrypt(:value => encrypted_value, :key => secret_key) # 'some string to encrypt'
|
19
19
|
|
20
20
|
You may also pass the `:iv` and `:algorithm` options but they are not required. If an algorithm is not specified, the Encryptor uses
|
21
|
-
the algorithm found at `Huberry::Encryptor.
|
22
|
-
by overwriting this attribute:
|
21
|
+
the algorithm found at `Huberry::Encryptor.default_options[:algorithm]` which is `aes-256-cbc` by default. You can change the default options
|
22
|
+
by overwriting or merging this attribute:
|
23
23
|
|
24
|
-
Huberry::Encryptor.
|
24
|
+
Huberry::Encryptor.default_options.merge!(:algorithm => 'bf', :key => 'some default secret key')
|
25
25
|
|
26
26
|
Run `openssl list-cipher-commands` in your terminal to view a list all cipher algorithms that are supported on your platform.
|
27
27
|
|
28
|
+
aes-128-cbc
|
29
|
+
aes-128-ecb
|
30
|
+
aes-192-cbc
|
31
|
+
aes-192-ecb
|
32
|
+
aes-256-cbc
|
33
|
+
aes-256-ecb
|
34
|
+
base64
|
35
|
+
bf
|
36
|
+
bf-cbc
|
37
|
+
bf-cfb
|
38
|
+
bf-ecb
|
39
|
+
bf-ofb
|
40
|
+
cast
|
41
|
+
cast-cbc
|
42
|
+
cast5-cbc
|
43
|
+
cast5-cfb
|
44
|
+
cast5-ecb
|
45
|
+
cast5-ofb
|
46
|
+
des
|
47
|
+
des-cbc
|
48
|
+
des-cfb
|
49
|
+
des-ecb
|
50
|
+
des-ede
|
51
|
+
des-ede-cbc
|
52
|
+
des-ede-cfb
|
53
|
+
des-ede-ofb
|
54
|
+
des-ede3
|
55
|
+
des-ede3-cbc
|
56
|
+
des-ede3-cfb
|
57
|
+
des-ede3-ofb
|
58
|
+
des-ofb
|
59
|
+
des3
|
60
|
+
desx
|
61
|
+
idea
|
62
|
+
idea-cbc
|
63
|
+
idea-cfb
|
64
|
+
idea-ecb
|
65
|
+
idea-ofb
|
66
|
+
rc2
|
67
|
+
rc2-40-cbc
|
68
|
+
rc2-64-cbc
|
69
|
+
rc2-cbc
|
70
|
+
rc2-cfb
|
71
|
+
rc2-ecb
|
72
|
+
rc2-ofb
|
73
|
+
rc4
|
74
|
+
rc4-40
|
75
|
+
|
28
76
|
|
29
77
|
Contact
|
30
78
|
-------
|
data/lib/encryptor.rb
CHANGED
@@ -2,13 +2,13 @@ require 'openssl'
|
|
2
2
|
|
3
3
|
module Huberry
|
4
4
|
module Encryptor
|
5
|
-
# The default
|
5
|
+
# The default options to use when calling the <tt>encrypt</tt> and <tt>decrypt</tt> methods
|
6
6
|
#
|
7
|
-
# Defaults to 'aes-256-cbc'
|
7
|
+
# Defaults to { :algorithm => 'aes-256-cbc' }
|
8
8
|
#
|
9
9
|
# Run 'openssl list-cipher-commands' in your terminal to view a list all cipher algorithms that are supported on your platform
|
10
|
-
class << self; attr_accessor :
|
11
|
-
self.
|
10
|
+
class << self; attr_accessor :default_options; end
|
11
|
+
self.default_options = { :algorithm => 'aes-256-cbc' }
|
12
12
|
|
13
13
|
# Encrypts a <tt>:value</tt> with a specified <tt>:key</tt>
|
14
14
|
#
|
@@ -35,7 +35,8 @@ module Huberry
|
|
35
35
|
protected
|
36
36
|
|
37
37
|
def self.crypt(cipher_method, options = {})
|
38
|
-
|
38
|
+
options = default_options.merge(options)
|
39
|
+
cipher = OpenSSL::Cipher::Cipher.new(options[:algorithm])
|
39
40
|
cipher.send(cipher_method)
|
40
41
|
if options[:iv]
|
41
42
|
cipher.key = options[:key]
|
data/test/encryptor_test.rb
CHANGED
@@ -25,19 +25,19 @@ class EncryptorTest < Test::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
|
27
27
|
define_method 'test_should_have_a_default_algorithm' do
|
28
|
-
assert algorithms.include?(Huberry::Encryptor.
|
28
|
+
assert algorithms.include?(Huberry::Encryptor.default_options[:algorithm])
|
29
29
|
end
|
30
30
|
|
31
31
|
define_method 'test_should_use_the_default_algorithm_if_one_is_not_specified' do
|
32
|
-
assert_equal Huberry::Encryptor.encrypt(:value => original_value, :key => key, :algorithm => Huberry::Encryptor.
|
32
|
+
assert_equal Huberry::Encryptor.encrypt(:value => original_value, :key => key, :algorithm => Huberry::Encryptor.default_options[:algorithm]), Huberry::Encryptor.encrypt(:value => original_value, :key => key)
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_should_be_able_to_change_the_default_algorithm
|
36
|
-
original_algorithm = Huberry::Encryptor.
|
36
|
+
original_algorithm = Huberry::Encryptor.default_options[:algorithm]
|
37
37
|
assert_not_equal 'test', original_algorithm
|
38
|
-
Huberry::Encryptor.
|
39
|
-
assert_equal 'test', Huberry::Encryptor.
|
40
|
-
Huberry::Encryptor.
|
38
|
+
Huberry::Encryptor.default_options[:algorithm] = 'test'
|
39
|
+
assert_equal 'test', Huberry::Encryptor.default_options[:algorithm]
|
40
|
+
Huberry::Encryptor.default_options[:algorithm] = original_algorithm
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shuber-encryptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-10 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|