encrypted_strings 0.1.0 → 0.1.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.rdoc +6 -0
- data/README.rdoc +1 -1
- data/Rakefile +2 -2
- data/lib/encrypted_strings/asymmetric_encryptor.rb +36 -22
- data/lib/encrypted_strings/extensions/string.rb +3 -3
- data/lib/encrypted_strings/sha_encryptor.rb +6 -2
- data/lib/encrypted_strings/symmetric_encryptor.rb +73 -37
- data/test/asymmetric_encryptor_test.rb +63 -34
- data/test/keys/encrypted_private +12 -12
- data/test/keys/pkcs5_encrypted_private +12 -0
- data/test/sha_encryptor_test.rb +21 -1
- data/test/string_test.rb +7 -7
- data/test/symmetric_encryptor_test.rb +86 -15
- metadata +19 -19
- data/test/keys/encrypted_public +0 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
== master
|
2
2
|
|
3
|
+
== 0.1.1 / 2008-12-01
|
4
|
+
|
5
|
+
* Fix non-compliant PKCS #5 algorithm being used for symmetric encryption. Use :pkcs5_compliant => true for better security.
|
6
|
+
* Rename SymmetricEncryptor#key to #password
|
7
|
+
* Fix deprecation messages for Cipher#encrypt/decrypt
|
8
|
+
|
3
9
|
== 0.1.0 / 2008-07-06
|
4
10
|
|
5
11
|
* Remove dependency on active_support
|
data/README.rdoc
CHANGED
@@ -57,7 +57,7 @@ the resulting encrypted value is the same.
|
|
57
57
|
|
58
58
|
>> password = "shhhh"
|
59
59
|
=> "shhhh"
|
60
|
-
>> crypted_password = password.encrypt(:symmetric, :
|
60
|
+
>> crypted_password = password.encrypt(:symmetric, :password => "secret_key")
|
61
61
|
=> "jDACXI5hMPI=\n"
|
62
62
|
>> crypted_password.class
|
63
63
|
=> String
|
data/Rakefile
CHANGED
@@ -5,11 +5,11 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'encrypted_strings'
|
8
|
-
s.version = '0.1.
|
8
|
+
s.version = '0.1.1'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = 'Dead-simple string encryption/decryption syntax.'
|
11
11
|
|
12
|
-
s.files = FileList['{lib,test}/**/*']
|
12
|
+
s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
|
13
13
|
s.require_path = 'lib'
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.test_files = Dir['test/**/*_test.rb']
|
@@ -38,28 +38,32 @@ module PluginAWeek #:nodoc:
|
|
38
38
|
#
|
39
39
|
# PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = "./private.key"
|
40
40
|
# PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm = "DES-EDE3-CBC"
|
41
|
-
# PluginAWeek::EncryptedStrings::SymmetricEncryptor.
|
41
|
+
# PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = "secret"
|
42
42
|
#
|
43
43
|
# If these configuration options are not passed in to #decrypt, then the
|
44
44
|
# default values will be used. You can override the default values like so:
|
45
45
|
#
|
46
46
|
# password = "INy95irZ8AlHmvc6ZAF/ARsTpbqPIB/4bEAKKOebjsayB7NYWtIzpswvzxqf\nNJ5yyuvxfMODrcg7RimEMFkFlg==\n"
|
47
|
-
# password.decrypt(:asymmetric, :public_key_file => "./encrypted_public.key", :
|
47
|
+
# password.decrypt(:asymmetric, :public_key_file => "./encrypted_public.key", :password => "secret") # => "shhhh"
|
48
48
|
#
|
49
49
|
# An exception will be raised if either the private key file could not be
|
50
50
|
# found or the key could not decrypt the private key file.
|
51
51
|
class AsymmetricEncryptor < Encryptor
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
class << self
|
53
|
+
# The default private key to use during encryption. Default is nil.
|
54
|
+
attr_accessor :default_private_key_file
|
55
|
+
|
56
|
+
# The default public key to use during encryption. Default is nil.
|
57
|
+
attr_accessor :default_public_key_file
|
58
|
+
|
59
|
+
# The default algorithm to use. Default is nil.
|
60
|
+
attr_accessor :default_algorithm
|
61
|
+
end
|
55
62
|
|
56
|
-
#
|
63
|
+
# Set defaults
|
64
|
+
@default_private_key_file = nil
|
57
65
|
@default_public_key_file = nil
|
58
|
-
class << self; attr_accessor :default_public_key_file; end
|
59
|
-
|
60
|
-
# The default algorithm to use. Default is nil.
|
61
66
|
@default_algorithm = nil
|
62
|
-
class << self; attr_accessor :default_algorithm; end
|
63
67
|
|
64
68
|
# Private key used for decrypting data
|
65
69
|
attr_reader :private_key_file
|
@@ -70,30 +74,36 @@ module PluginAWeek #:nodoc:
|
|
70
74
|
# The algorithm to use if the key files are encrypted themselves
|
71
75
|
attr_accessor :algorithm
|
72
76
|
|
73
|
-
# The
|
74
|
-
attr_accessor :
|
77
|
+
# The password used during symmetric decryption of the key files
|
78
|
+
attr_accessor :password
|
75
79
|
|
76
80
|
# Configuration options:
|
77
81
|
# * +private_key_file+ - Encrypted private key file
|
78
82
|
# * +public_key_file+ - Public key file
|
79
|
-
# * +
|
83
|
+
# * +password+ - The password to use in the symmetric encryptor
|
84
|
+
# * +key+ - DEPRECATED. The password to use in the symmetric encryptor
|
80
85
|
# * +algorithm+ - Algorithm to use symmetrically encrypted strings
|
86
|
+
# * +pkcs5_compliant+ - Whether the generated key/iv should comply to the PKCS #5 standard. Default is false.
|
81
87
|
def initialize(options = {})
|
82
|
-
invalid_options = options.keys - [:private_key_file, :public_key_file, :key, :algorithm]
|
88
|
+
invalid_options = options.keys - [:private_key_file, :public_key_file, :password, :key, :algorithm, :pkcs5_compliant]
|
83
89
|
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
|
84
90
|
|
85
91
|
options = {
|
86
|
-
:private_key_file =>
|
87
|
-
:public_key_file =>
|
88
|
-
:algorithm =>
|
92
|
+
:private_key_file => self.class.default_private_key_file,
|
93
|
+
:public_key_file => self.class.default_public_key_file,
|
94
|
+
:algorithm => self.class.default_algorithm
|
89
95
|
}.merge(options)
|
90
96
|
|
91
97
|
@public_key = @private_key = nil
|
92
98
|
|
93
|
-
self.key = options[:key]
|
94
99
|
self.algorithm = options[:algorithm]
|
95
100
|
self.private_key_file = options[:private_key_file]
|
96
101
|
self.public_key_file = options[:public_key_file]
|
102
|
+
self.password = options[:password] || options[:key]
|
103
|
+
warn(':key option is deprecated and will be removed from encrypted_attributes 0.2.0 (use :password)') if options[:key]
|
104
|
+
@pkcs5_compliant = options[:pkcs5_compliant]
|
105
|
+
|
106
|
+
raise ArgumentError, 'At least one key file must be specified (:private_key_file or :public_key_file)' unless private_key_file || public_key_file
|
97
107
|
|
98
108
|
super()
|
99
109
|
end
|
@@ -148,7 +158,7 @@ module PluginAWeek #:nodoc:
|
|
148
158
|
@private_rsa = nil
|
149
159
|
|
150
160
|
if private_key_file && File.file?(private_key_file)
|
151
|
-
@private_key = File.
|
161
|
+
@private_key = File.read(private_key_file)
|
152
162
|
end
|
153
163
|
end
|
154
164
|
|
@@ -157,14 +167,18 @@ module PluginAWeek #:nodoc:
|
|
157
167
|
@public_rsa = nil
|
158
168
|
|
159
169
|
if public_key_file && File.file?(public_key_file)
|
160
|
-
@public_key = File.
|
170
|
+
@public_key = File.read(public_key_file)
|
161
171
|
end
|
162
172
|
end
|
163
173
|
|
164
174
|
# Retrieves the private RSA from the private key
|
165
175
|
def private_rsa
|
166
|
-
if
|
167
|
-
|
176
|
+
if password
|
177
|
+
options = {:password => password}
|
178
|
+
options[:algorithm] = algorithm if algorithm
|
179
|
+
options[:pkcs5_compliant] = @pkcs5_compliant if !@pkcs5_compliant.nil?
|
180
|
+
|
181
|
+
private_key = @private_key.decrypt(:symmetric, options)
|
168
182
|
OpenSSL::PKey::RSA.new(private_key)
|
169
183
|
else
|
170
184
|
@private_rsa ||= OpenSSL::PKey::RSA.new(@private_key)
|
@@ -60,7 +60,7 @@ module PluginAWeek #:nodoc:
|
|
60
60
|
# == Example
|
61
61
|
#
|
62
62
|
# password = 'shhhh'
|
63
|
-
# password.encrypt!(:symmetric, :
|
63
|
+
# password.encrypt!(:symmetric, :password => 'my_key') # => "jDACXI5hMPI=\n"
|
64
64
|
# password # => "jDACXI5hMPI=\n"
|
65
65
|
def encrypt!(*args)
|
66
66
|
encrypted_string = encrypt(*args)
|
@@ -89,7 +89,7 @@ module PluginAWeek #:nodoc:
|
|
89
89
|
# == Example
|
90
90
|
#
|
91
91
|
# password = "jDACXI5hMPI=\n"
|
92
|
-
# password.decrypt(:symmetric, :
|
92
|
+
# password.decrypt(:symmetric, :password => 'my_key') # => "shhhh"
|
93
93
|
def decrypt(*args)
|
94
94
|
raise ArgumentError, "An encryption algorithm must be specified since we can't figure it out" if args.empty? && !@encryptor
|
95
95
|
|
@@ -107,7 +107,7 @@ module PluginAWeek #:nodoc:
|
|
107
107
|
# For example,
|
108
108
|
#
|
109
109
|
# password = "jDACXI5hMPI=\n"
|
110
|
-
# password.decrypt!(:symmetric, :
|
110
|
+
# password.decrypt!(:symmetric, :password => 'my_key') # => "shhhh"
|
111
111
|
# password # => "shhhh"
|
112
112
|
def decrypt!(*args)
|
113
113
|
value = replace(decrypt(*args))
|
@@ -28,9 +28,13 @@ module PluginAWeek #:nodoc:
|
|
28
28
|
# input = "shhhh".encrypt(:sha, :salt => "secret") # => "3b22cbe4acde873c3efc82681096f3ae69aff828"
|
29
29
|
# password == input # => true
|
30
30
|
class ShaEncryptor < Encryptor
|
31
|
-
|
31
|
+
class << self
|
32
|
+
# The default salt value to use during encryption
|
33
|
+
attr_accessor :default_salt
|
34
|
+
end
|
35
|
+
|
36
|
+
# Set defaults
|
32
37
|
@default_salt = 'salt'
|
33
|
-
class << self; attr_accessor :default_salt; end
|
34
38
|
|
35
39
|
# The salt value to use for encryption
|
36
40
|
attr_accessor :salt
|
@@ -2,96 +2,132 @@ require 'encrypted_strings/no_key_error'
|
|
2
2
|
|
3
3
|
module PluginAWeek #:nodoc:
|
4
4
|
module EncryptedStrings
|
5
|
-
# Symmetric encryption uses a
|
6
|
-
# string. As long as the
|
7
|
-
# decrypted.
|
5
|
+
# Symmetric encryption uses a password and a specific algorithm to encrypt
|
6
|
+
# the string. As long as the password and algorithm are known, the string
|
7
|
+
# can be decrypted.
|
8
8
|
#
|
9
9
|
# Source: http://support.microsoft.com/kb/246071
|
10
10
|
#
|
11
11
|
# == Encrypting
|
12
12
|
#
|
13
13
|
# To encrypt a string using a symmetric algorithm, the type of algorithm and
|
14
|
-
#
|
15
|
-
# so:
|
14
|
+
# password *must* be specified. You can define the defaults for these
|
15
|
+
# values like so:
|
16
16
|
#
|
17
17
|
# PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm = 'des-ecb'
|
18
|
-
# PluginAWeek::EncryptedStrings::SymmetricEncryptor.
|
18
|
+
# PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = 'secret'
|
19
19
|
#
|
20
20
|
# If these configuration options are not passed in to #encrypt, then the
|
21
21
|
# default values will be used. You can override the default values like so:
|
22
22
|
#
|
23
23
|
# password = 'shhhh'
|
24
|
-
# password.encrypt(:symmetric, :algorithm => 'des-ecb', :
|
24
|
+
# password.encrypt(:symmetric, :algorithm => 'des-ecb', :password => 'secret') # => "sUG6tYSn0mI=\n"
|
25
25
|
#
|
26
|
-
# An exception will be raised if no
|
26
|
+
# An exception will be raised if no password is specified.
|
27
27
|
#
|
28
28
|
# == Decrypting
|
29
29
|
#
|
30
30
|
# To decrypt a string using an symmetric algorithm, the type of algorithm
|
31
|
-
# and
|
32
|
-
# as show above.
|
31
|
+
# and password must also be specified. Defaults for these values can be
|
32
|
+
# defined as show above.
|
33
33
|
#
|
34
34
|
# If these configuration options are not passed in to #decrypt, then the
|
35
35
|
# default values will be used. You can override the default values like so:
|
36
36
|
#
|
37
37
|
# password = "sUG6tYSn0mI=\n"
|
38
|
-
# password.decrypt(:symmetric, :algorithm => 'des-ecb', :
|
38
|
+
# password.decrypt(:symmetric, :algorithm => 'des-ecb', :password => 'secret') # => "shhhh"
|
39
39
|
#
|
40
|
-
# An exception will be raised if no
|
40
|
+
# An exception will be raised if no password is specified.
|
41
41
|
class SymmetricEncryptor < Encryptor
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
class << self
|
43
|
+
# The default algorithm to use for encryption. Default is DES-EDE3-CBC.
|
44
|
+
attr_accessor :default_algorithm
|
45
|
+
|
46
|
+
# The default password to use for generating the key and initialization
|
47
|
+
# vector. Default is nil.
|
48
|
+
attr_accessor :default_password
|
49
|
+
|
50
|
+
# DEPRECATED
|
51
|
+
def default_key #:nodoc:
|
52
|
+
warn("#{self}.default_key is deprecated and will be removed from encrypted_attributes 0.2.0 (use default_password)")
|
53
|
+
@default_password
|
54
|
+
end
|
55
|
+
|
56
|
+
# DEPRECATED
|
57
|
+
def default_key=(value) #:nodoc:
|
58
|
+
warn("#{self}.default_key= is deprecated and will be removed from encrypted_attributes 0.2.0 (use default_password=)")
|
59
|
+
@default_password = value
|
60
|
+
end
|
61
|
+
end
|
45
62
|
|
46
|
-
#
|
47
|
-
@
|
48
|
-
|
63
|
+
# Set default values
|
64
|
+
@default_algorithm = 'DES-EDE3-CBC'
|
65
|
+
@default_password = nil
|
49
66
|
|
50
67
|
# The algorithm to use for encryption/decryption
|
51
68
|
attr_accessor :algorithm
|
52
69
|
|
53
|
-
# The
|
54
|
-
|
70
|
+
# The password that generates the key/initialization vector for the
|
71
|
+
# algorithm
|
72
|
+
attr_accessor :password
|
55
73
|
|
56
74
|
# Configuration options:
|
57
|
-
# * +
|
58
|
-
# * +
|
75
|
+
# * +algorithm+ - The algorithm to use
|
76
|
+
# * +password+ - The secret key to use for generating the key/initialization vector for the algorithm
|
77
|
+
# * +key+ - DEPRECATED. The secret key to use for generating the key/initialization vector for the algorithm
|
78
|
+
# * +pkcs5_compliant+ - Whether the generated key/iv should comply to the PKCS #5 standard. Default is false.
|
59
79
|
def initialize(options = {})
|
60
|
-
invalid_options = options.keys - [:key, :
|
80
|
+
invalid_options = options.keys - [:algorithm, :password, :key, :pkcs5_compliant]
|
61
81
|
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
|
62
82
|
|
63
83
|
options = {
|
64
|
-
:
|
65
|
-
:
|
84
|
+
:algorithm => self.class.default_algorithm,
|
85
|
+
:password => self.class.default_password,
|
86
|
+
:pkcs5_compliant => false
|
66
87
|
}.merge(options)
|
67
88
|
|
68
|
-
|
69
|
-
|
89
|
+
@pkcs5_compliant = options[:pkcs5_compliant]
|
90
|
+
warn('PKCS #5 non-compliancy is deprecated and will be removed from encrypted_attributes 0.2.0') if @pkcs5_compliant == false
|
70
91
|
|
71
92
|
self.algorithm = options[:algorithm]
|
72
93
|
|
94
|
+
self.password = options[:password] || options[:key]
|
95
|
+
warn(':key option is deprecated and will be removed from encrypted_attributes 0.2.0 (use :password)') if options[:key]
|
96
|
+
raise NoKeyError if password.nil?
|
97
|
+
|
73
98
|
super()
|
74
99
|
end
|
75
100
|
|
76
101
|
# Decrypts the current string using the current key and algorithm specified
|
77
102
|
def decrypt(data)
|
78
|
-
cipher
|
79
|
-
|
80
|
-
decrypted_data << cipher.final
|
103
|
+
cipher = build_cipher(:decrypt)
|
104
|
+
cipher.update(Base64.decode64(data)) + cipher.final
|
81
105
|
end
|
82
106
|
|
83
107
|
# Encrypts the current string using the current key and algorithm specified
|
84
108
|
def encrypt(data)
|
85
|
-
cipher
|
86
|
-
|
87
|
-
encrypted_data << cipher.final
|
88
|
-
|
89
|
-
Base64.encode64(encrypted_data)
|
109
|
+
cipher = build_cipher(:encrypt)
|
110
|
+
Base64.encode64(cipher.update(data) + cipher.final)
|
90
111
|
end
|
91
112
|
|
92
113
|
private
|
93
|
-
def
|
94
|
-
|
114
|
+
def build_cipher(type) #:nodoc:
|
115
|
+
cipher = OpenSSL::Cipher.new(algorithm)
|
116
|
+
cipher.send(type)
|
117
|
+
|
118
|
+
if @pkcs5_compliant
|
119
|
+
# Use the default PKCS5 key/iv generator algorithm
|
120
|
+
cipher.pkcs5_keyivgen(password)
|
121
|
+
else
|
122
|
+
# To remain backwards-compatible, the deprecated #encrypt/#decrypt
|
123
|
+
# calls (which take a single argument, being the password) is replaced
|
124
|
+
# with pkcs5_keyivgen. Internally, this uses "OpenSSL for Ruby rulez!"
|
125
|
+
# as the IV/salt. This is also the case for the number of iterations.
|
126
|
+
cipher.pkcs5_keyivgen(password, 'OpenSSL ', 1)
|
127
|
+
cipher.iv = 'OpenSSL for Ruby rulez!'
|
128
|
+
end
|
129
|
+
|
130
|
+
cipher
|
95
131
|
end
|
96
132
|
end
|
97
133
|
end
|
@@ -2,6 +2,37 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/public')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_should_raise_an_exception
|
9
|
+
assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_not_have_a_public_key_file
|
13
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/private')
|
14
|
+
assert_nil @asymmetric_encryptor.public_key_file
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_not_have_a_private_key_file
|
18
|
+
assert_nil @asymmetric_encryptor.private_key_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_not_have_an_algorithm
|
22
|
+
assert_nil @asymmetric_encryptor.algorithm
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_not_have_a_password
|
26
|
+
assert_nil @asymmetric_encryptor.password
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class AsymmetricEncryptorWithCustomDefaultsTest < Test::Unit::TestCase
|
31
|
+
def setup
|
32
|
+
@original_default_public_key_file = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file
|
33
|
+
@original_default_private_key_file = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file
|
34
|
+
@original_default_algorithm = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm
|
35
|
+
|
5
36
|
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = File.dirname(__FILE__) + '/keys/public'
|
6
37
|
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = File.dirname(__FILE__) + '/keys/private'
|
7
38
|
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm = 'DES-EDE3-CBC'
|
@@ -9,11 +40,11 @@ class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
|
9
40
|
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
|
10
41
|
end
|
11
42
|
|
12
|
-
def
|
43
|
+
def test_should_use_default_public_key_file
|
13
44
|
assert_equal File.dirname(__FILE__) + '/keys/public', @asymmetric_encryptor.public_key_file
|
14
45
|
end
|
15
46
|
|
16
|
-
def
|
47
|
+
def test_should_use_default_private_key_file
|
17
48
|
assert_equal File.dirname(__FILE__) + '/keys/private', @asymmetric_encryptor.private_key_file
|
18
49
|
end
|
19
50
|
|
@@ -21,14 +52,14 @@ class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
|
21
52
|
assert_equal 'DES-EDE3-CBC', @asymmetric_encryptor.algorithm
|
22
53
|
end
|
23
54
|
|
24
|
-
def
|
25
|
-
assert_nil @asymmetric_encryptor.
|
55
|
+
def test_should_not_have_a_password
|
56
|
+
assert_nil @asymmetric_encryptor.password
|
26
57
|
end
|
27
58
|
|
28
59
|
def teardown
|
29
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file =
|
30
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file =
|
31
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm =
|
60
|
+
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = @original_default_public_key_file
|
61
|
+
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = @original_default_private_key_file
|
62
|
+
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm = @original_default_algorithm
|
32
63
|
end
|
33
64
|
end
|
34
65
|
|
@@ -40,7 +71,7 @@ end
|
|
40
71
|
|
41
72
|
class AsymmetricEncryptorTest < Test::Unit::TestCase
|
42
73
|
def setup
|
43
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
|
74
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/public')
|
44
75
|
end
|
45
76
|
|
46
77
|
def test_should_be_able_to_decrypt
|
@@ -50,7 +81,7 @@ end
|
|
50
81
|
|
51
82
|
class AsymmetricEncryptorWithoutPublicKeyTest < Test::Unit::TestCase
|
52
83
|
def setup
|
53
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => nil)
|
84
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => nil, :private_key_file => File.dirname(__FILE__) + '/keys/private')
|
54
85
|
end
|
55
86
|
|
56
87
|
def test_should_not_be_public
|
@@ -86,7 +117,7 @@ end
|
|
86
117
|
|
87
118
|
class AsymmetricEncryptorWithoutPrivateKeyTest < Test::Unit::TestCase
|
88
119
|
def setup
|
89
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => nil)
|
120
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => nil, :public_key_file => File.dirname(__FILE__) + '/keys/public')
|
90
121
|
end
|
91
122
|
|
92
123
|
def test_should_not_be_private
|
@@ -94,7 +125,7 @@ class AsymmetricEncryptorWithoutPrivateKeyTest < Test::Unit::TestCase
|
|
94
125
|
end
|
95
126
|
|
96
127
|
def test_should_not_be_able_to_decrypt
|
97
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("
|
128
|
+
assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")}
|
98
129
|
end
|
99
130
|
end
|
100
131
|
|
@@ -120,46 +151,44 @@ class AsymmetricEncryptorWithPrivateKeyTest < Test::Unit::TestCase
|
|
120
151
|
end
|
121
152
|
end
|
122
153
|
|
123
|
-
class
|
154
|
+
class AsymmetricEncryptorWithEncryptedPrivateKeyTest < Test::Unit::TestCase
|
124
155
|
def setup
|
125
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:
|
156
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/encrypted_private', :algorithm => 'DES-EDE3-CBC', :password => 'secret')
|
126
157
|
end
|
127
158
|
|
128
|
-
def
|
129
|
-
assert
|
159
|
+
def test_should_not_be_public
|
160
|
+
assert !@asymmetric_encryptor.public?
|
130
161
|
end
|
131
162
|
|
132
|
-
def
|
133
|
-
assert
|
163
|
+
def test_should_be_private
|
164
|
+
assert @asymmetric_encryptor.private?
|
134
165
|
end
|
135
166
|
|
136
|
-
def
|
137
|
-
|
167
|
+
def test_should_not_be_able_to_encrypt
|
168
|
+
assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
|
138
169
|
end
|
139
170
|
|
140
|
-
def
|
141
|
-
|
171
|
+
def test_should_be_able_to_decrypt
|
172
|
+
assert_equal 'test', @asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")
|
142
173
|
end
|
143
174
|
end
|
144
175
|
|
145
|
-
class
|
176
|
+
class AsymmetricEncryptorWithPKCS5CompliancyTest < Test::Unit::TestCase
|
146
177
|
def setup
|
147
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_should_not_be_public
|
151
|
-
assert !@asymmetric_encryptor.public?
|
178
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/pkcs5_encrypted_private', :algorithm => 'DES-EDE3-CBC', :password => 'secret', :pkcs5_compliant => true)
|
152
179
|
end
|
153
180
|
|
154
|
-
def
|
155
|
-
|
181
|
+
def test_should_be_able_to_decrypt
|
182
|
+
assert_equal 'test', @asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")
|
156
183
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
184
|
+
end
|
185
|
+
|
186
|
+
class AsymmetricEncyrptorWithDeprecatedKeyTest < Test::Unit::TestCase
|
187
|
+
def setup
|
188
|
+
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/encrypted_private', :key => 'secret')
|
160
189
|
end
|
161
190
|
|
162
|
-
def
|
163
|
-
assert_equal '
|
191
|
+
def test_should_set_password
|
192
|
+
assert_equal 'secret', @asymmetric_encryptor.password
|
164
193
|
end
|
165
194
|
end
|
data/test/keys/encrypted_private
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
OBNa1q8kbx8pyZZjIpr/pZV0oulE2czh5JlPW/
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
OBNa1q8kbx8pyZZjIpr/pZV0oulE2czh5JlPW/13XsDKYjIwiLkCTZI5Vhv5
|
2
|
+
cCF+wQuNvrbnp/QvJGzc5aJK1GwxqEb9hAwCzxw69DVjIhUowXDk/rYWUaTq
|
3
|
+
YwpieO1v6gQrOVxerOubR7LT6A4I6k1CTECX6zeJeGgT2jOfXzIii0T1gmYD
|
4
|
+
tJxLlNclpGB+eS+tuwrfyNmE4CkYa5vjuWdxHAeMRXPlm+o3ErE0QZ36Sn51
|
5
|
+
TScPDsZHo7Ppit87sPXpubM/5JltN0QwV4Hj9dJoSm0QNWDb3BoyT1uuJ0wm
|
6
|
+
b/adzINN1oUjdgMB9g3kmkErS3MRJtuPRNuU7/GvAuv78pQ5tAdkvk8gu7Cd
|
7
|
+
5cFgnzvE7l96oZB6TXgsnpjVLide61Di+mX8K2dvUdoCNgrQ1iPklTbEfJeH
|
8
|
+
U/GoUV1ZyVnEfHkeWBEmC8YVBeri+lFL923g7z29luhxiBRkhows8TQsQ4hX
|
9
|
+
SMlFCKCKWKW2/58aSlvj0INa4NiBwkY987/X7VYvnSm747vOcD8Xmnd0Qwvt
|
10
|
+
weC2/NK11NFTNBIIodqsbvtlt1Ff0SXrO5PfbDU1yY+xzbx7SAwqhImXwScS
|
11
|
+
4b0nFpArdfeVKNp5teSiu050m4B8kb2EjPW7NISui5NXxWtU5Mu41EnenGES
|
12
|
+
CkHsLI3plvL/
|
@@ -0,0 +1,12 @@
|
|
1
|
+
TGr8Jm/7zh1dfjjoNJtOncvX/BdUL47b8k2rQbMTY7VD6ZpD317NTuVX1hHV
|
2
|
+
54Nm6pnCId5wcga3sI3TqolTxkqKBy7Rb1mPVBeJyd7ZuoD7zp65+ws+o4Lr
|
3
|
+
Xn/3WculfuThUnDESqD53vnKPCfRK6hoMDygEV7urmuide5ogpZp52lidUku
|
4
|
+
cXOHDqfVETX7NNnHHghg/6qDUX7+0qf+XeKe8uiI0cPoE5YFnOHyF7oOBGtR
|
5
|
+
IqJG97q1InCJMeAbMSxcjO71Te51Z098yI+XN4rGmXbmzSrVKHMUk0tdsVxi
|
6
|
+
CE5OmnzLeXK1xomxkRmXZzl10WDBn9e4knoLJTlDdNR3fA4gLRfy3r6RBlDl
|
7
|
+
j7HI53o5gi9PTshSXwHr6Q8SV9fty2Nz3/yRT/ZPLUJC1GUqErLl2j6zYbVR
|
8
|
+
8YMaLt1Zqi79ycPZxZV4Zh57YE86nUqepS1pzVpcS8dHZMne846lTyaOyxZ8
|
9
|
+
dxW+18s7E7KqpHj17QYrF6c7R5ZHgoNAbLFeGSUCXqkW8YdyidLqQTzWN7hF
|
10
|
+
roVcZWFe8YfSUKmgndVBOHGHxMGr+OYgVdAStOEwmRHaNGgSBE4FCkKXYJUj
|
11
|
+
ec3zNpiOCb8zxfNku5nT5nIHnGqO4JKWDvDGVioV+ffHwXpAw3OFE5n+M/uo
|
12
|
+
4ZZbVSh1qZxd
|
data/test/sha_encryptor_test.rb
CHANGED
@@ -14,6 +14,26 @@ class ShaEncryptorByDefaulTest < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
class ShaEncryptorWithCustomDefaultsTest < Test::Unit::TestCase
|
18
|
+
def setup
|
19
|
+
@original_default_salt = PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt
|
20
|
+
PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt = 'custom_salt'
|
21
|
+
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_use_custom_default_salt
|
25
|
+
assert_equal 'custom_salt', @sha_encryptor.salt
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_encrypt_using_custom_default_salt
|
29
|
+
assert_equal '280f3c516070b09aa3eb755378509c725a9c6561', @sha_encryptor.encrypt('test')
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt = @original_default_salt
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
17
37
|
class ShaEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
|
18
38
|
def test_should_throw_an_exception
|
19
39
|
assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::ShaEncryptor.new(:invalid => true)}
|
@@ -34,7 +54,7 @@ class ShaEncryptorTest < Test::Unit::TestCase
|
|
34
54
|
end
|
35
55
|
end
|
36
56
|
|
37
|
-
class
|
57
|
+
class ShaEncryptorWithCustomOptionsTest < Test::Unit::TestCase
|
38
58
|
def setup
|
39
59
|
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => 'different salt')
|
40
60
|
end
|
data/test/string_test.rb
CHANGED
@@ -26,7 +26,7 @@ end
|
|
26
26
|
|
27
27
|
class StringWithCustomEncryptor
|
28
28
|
def setup
|
29
|
-
@encrypted_string = 'test'.encrypt(:symmetric, :
|
29
|
+
@encrypted_string = 'test'.encrypt(:symmetric, :password => 'key')
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_should_use_custom_encryptor
|
@@ -83,7 +83,7 @@ end
|
|
83
83
|
|
84
84
|
class StringAfterBeingDecryptedTest < Test::Unit::TestCase
|
85
85
|
def setup
|
86
|
-
@encrypted_string = 'test'.encrypt(:symmetric, :
|
86
|
+
@encrypted_string = 'test'.encrypt(:symmetric, :password => 'secret')
|
87
87
|
@decrypted_string = @encrypted_string.decrypt
|
88
88
|
end
|
89
89
|
|
@@ -98,7 +98,7 @@ end
|
|
98
98
|
|
99
99
|
class StringAfterBeingDecryptedAndReplacedTest < Test::Unit::TestCase
|
100
100
|
def setup
|
101
|
-
@encrypted_string = 'test'.encrypt(:symmetric, :
|
101
|
+
@encrypted_string = 'test'.encrypt(:symmetric, :password => 'secret')
|
102
102
|
@encrypted_string.decrypt!
|
103
103
|
end
|
104
104
|
|
@@ -163,7 +163,7 @@ end
|
|
163
163
|
|
164
164
|
class StringWithDecryptableEncryptorTest < Test::Unit::TestCase
|
165
165
|
def setup
|
166
|
-
@encrypted_string = 'test'.encrypt(:symmetric, :
|
166
|
+
@encrypted_string = 'test'.encrypt(:symmetric, :password => 'secret')
|
167
167
|
end
|
168
168
|
|
169
169
|
def test_should_be_able_to_decrypt
|
@@ -180,7 +180,7 @@ class StringWithDecryptableEncryptorTest < Test::Unit::TestCase
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def test_should_be_able_to_check_equality_with_encrypted_value_of_encrypted_string
|
183
|
-
encrypted_encrypted_string = @encrypted_string.encrypt(:symmetric, :
|
183
|
+
encrypted_encrypted_string = @encrypted_string.encrypt(:symmetric, :password => 'secret')
|
184
184
|
|
185
185
|
assert_equal @encrypted_string, encrypted_encrypted_string
|
186
186
|
assert_equal encrypted_encrypted_string, @encrypted_string
|
@@ -192,7 +192,7 @@ class StringWithDecryptableEncryptorTest < Test::Unit::TestCase
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def test_should_not_be_able_to_check_equality_more_than_one_encryption_away
|
195
|
-
encrypted_encrypted_string = @encrypted_string.encrypt(:symmetric, :
|
195
|
+
encrypted_encrypted_string = @encrypted_string.encrypt(:symmetric, :password => 'secret')
|
196
196
|
|
197
197
|
assert_not_equal 'test', encrypted_encrypted_string
|
198
198
|
assert_not_equal encrypted_encrypted_string, 'test'
|
@@ -217,6 +217,6 @@ class StringPreviouslyEncryptedTest < Test::Unit::TestCase
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def test_should_be_able_to_decrypt_with_custom_mode
|
220
|
-
assert_equal 'test', @encrypted_string.decrypt(:symmetric, :
|
220
|
+
assert_equal 'test', @encrypted_string.decrypt(:symmetric, :password => 'secret')
|
221
221
|
end
|
222
222
|
end
|
@@ -2,28 +2,55 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class SymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.
|
6
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new
|
5
|
+
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:password => 'secret')
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
assert_equal '
|
8
|
+
def test_should_use_default_algorithm
|
9
|
+
assert_equal 'DES-EDE3-CBC', @symmetric_encryptor.algorithm
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
14
|
-
|
12
|
+
def test_should_raise_exception
|
13
|
+
assert_raise(PluginAWeek::EncryptedStrings::NoKeyError) {PluginAWeek::EncryptedStrings::SymmetricEncryptor.new}
|
15
14
|
end
|
16
15
|
|
17
|
-
def
|
16
|
+
def test_should_encrypt_using_default_configuration
|
18
17
|
assert_equal "MU6e/5LvhKA=\n", @symmetric_encryptor.encrypt('test')
|
19
18
|
end
|
20
19
|
|
21
|
-
def
|
20
|
+
def test_should_decrypt_encrypted_string_using_default_configuration
|
22
21
|
assert_equal 'test', @symmetric_encryptor.decrypt("MU6e/5LvhKA=\n")
|
23
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class SymmetricEncryptorWithCustomDefaultsTest < Test::Unit::TestCase
|
26
|
+
def setup
|
27
|
+
@original_default_algorithm = PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm
|
28
|
+
@original_default_password = PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password
|
29
|
+
|
30
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm = 'DES-EDE3-CFB'
|
31
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = 'secret'
|
32
|
+
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_use_custom_default_algorithm
|
36
|
+
assert_equal 'DES-EDE3-CFB', @symmetric_encryptor.algorithm
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_use_custom_default_password
|
40
|
+
assert_equal 'secret', @symmetric_encryptor.password
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_encrypt_using_custom_default_configuration
|
44
|
+
assert_equal "C7D9mg==\n", @symmetric_encryptor.encrypt('test')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_decrypt_encrypted_string_using_custom_default_configuration
|
48
|
+
assert_equal 'test', @symmetric_encryptor.decrypt("C7D9mg==\n")
|
49
|
+
end
|
24
50
|
|
25
51
|
def teardown
|
26
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.
|
52
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm = @original_default_algorithm
|
53
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = @original_default_password
|
27
54
|
end
|
28
55
|
end
|
29
56
|
|
@@ -35,7 +62,7 @@ end
|
|
35
62
|
|
36
63
|
class SymmetricEncryptorTest < Test::Unit::TestCase
|
37
64
|
def setup
|
38
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:
|
65
|
+
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:password => 'secret')
|
39
66
|
end
|
40
67
|
|
41
68
|
def test_should_be_able_to_decrypt
|
@@ -45,17 +72,17 @@ end
|
|
45
72
|
|
46
73
|
class SymmetricEncryptorWithCustomOptionsTest < Test::Unit::TestCase
|
47
74
|
def setup
|
48
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_use_custom_key
|
52
|
-
assert_equal 'secret', @symmetric_encryptor.key
|
75
|
+
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:algorithm => 'DES-EDE3-CFB', :password => 'secret')
|
53
76
|
end
|
54
77
|
|
55
78
|
def test_should_use_custom_algorithm
|
56
79
|
assert_equal 'DES-EDE3-CFB', @symmetric_encryptor.algorithm
|
57
80
|
end
|
58
81
|
|
82
|
+
def test_should_use_custom_password
|
83
|
+
assert_equal 'secret', @symmetric_encryptor.password
|
84
|
+
end
|
85
|
+
|
59
86
|
def test_should_encrypt_using_custom_options
|
60
87
|
assert_equal "C7D9mg==\n", @symmetric_encryptor.encrypt('test')
|
61
88
|
end
|
@@ -64,3 +91,47 @@ class SymmetricEncryptorWithCustomOptionsTest < Test::Unit::TestCase
|
|
64
91
|
assert_equal 'test', @symmetric_encryptor.decrypt("C7D9mg==\n")
|
65
92
|
end
|
66
93
|
end
|
94
|
+
|
95
|
+
class SymmetricEncryptorWithPKCS5CompliancyTest < Test::Unit::TestCase
|
96
|
+
def setup
|
97
|
+
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:password => 'secret', :pkcs5_compliant => true)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_should_encrypt_using_pkcs5_generated_key
|
101
|
+
assert_equal "oTxJd67ElLY=\n", @symmetric_encryptor.encrypt('test')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_decrypt_using_pkcs5_generated_key
|
105
|
+
assert_equal 'test', @symmetric_encryptor.decrypt("oTxJd67ElLY=\n" )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class SymmetricEncryptorWithDeprecatedDefaultsTest < Test::Unit::TestCase
|
110
|
+
def setup
|
111
|
+
@original_default_password = PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_should_set_password_when_setting_key
|
115
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = 'secret'
|
116
|
+
assert_equal 'secret', PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_should_get_password_when_getting_key
|
120
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = 'secret'
|
121
|
+
assert_equal 'secret', PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key
|
122
|
+
end
|
123
|
+
|
124
|
+
def teardown
|
125
|
+
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = @original_default_password
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class SymmetricEncryptorWithDeprecatedKeyTest < Test::Unit::TestCase
|
130
|
+
def setup
|
131
|
+
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => 'secret')
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_should_set_password
|
135
|
+
assert_equal 'secret', @symmetric_encryptor.password
|
136
|
+
end
|
137
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encrypted_strings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-01 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,31 +22,31 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- lib/encrypted_strings.rb
|
26
25
|
- lib/encrypted_strings
|
27
|
-
- lib/encrypted_strings/
|
28
|
-
- lib/encrypted_strings/encryptor.rb
|
29
|
-
- lib/encrypted_strings/symmetric_encryptor.rb
|
30
|
-
- lib/encrypted_strings/no_public_key_error.rb
|
26
|
+
- lib/encrypted_strings/no_private_key_error.rb
|
31
27
|
- lib/encrypted_strings/asymmetric_encryptor.rb
|
32
28
|
- lib/encrypted_strings/sha_encryptor.rb
|
33
|
-
- lib/encrypted_strings/no_private_key_error.rb
|
34
29
|
- lib/encrypted_strings/extensions
|
35
30
|
- lib/encrypted_strings/extensions/string.rb
|
31
|
+
- lib/encrypted_strings/encryptor.rb
|
32
|
+
- lib/encrypted_strings/no_key_error.rb
|
33
|
+
- lib/encrypted_strings/no_public_key_error.rb
|
34
|
+
- lib/encrypted_strings/symmetric_encryptor.rb
|
35
|
+
- lib/encrypted_strings.rb
|
36
|
+
- test/asymmetric_encryptor_test.rb
|
36
37
|
- test/symmetric_encryptor_test.rb
|
37
|
-
- test/
|
38
|
+
- test/test_helper.rb
|
39
|
+
- test/no_key_error_test.rb
|
38
40
|
- test/sha_encryptor_test.rb
|
41
|
+
- test/no_private_key_error_test.rb
|
39
42
|
- test/keys
|
40
43
|
- test/keys/encrypted_private
|
41
44
|
- test/keys/private
|
42
45
|
- test/keys/public
|
43
|
-
- test/keys/
|
44
|
-
- test/no_key_error_test.rb
|
45
|
-
- test/test_helper.rb
|
46
|
+
- test/keys/pkcs5_encrypted_private
|
46
47
|
- test/string_test.rb
|
47
|
-
- test/
|
48
|
+
- test/no_public_key_error_test.rb
|
48
49
|
- test/encryptor_test.rb
|
49
|
-
- test/no_private_key_error_test.rb
|
50
50
|
- CHANGELOG.rdoc
|
51
51
|
- init.rb
|
52
52
|
- LICENSE
|
@@ -74,16 +74,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
requirements: []
|
75
75
|
|
76
76
|
rubyforge_project: pluginaweek
|
77
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.2.0
|
78
78
|
signing_key:
|
79
79
|
specification_version: 2
|
80
80
|
summary: Dead-simple string encryption/decryption syntax.
|
81
81
|
test_files:
|
82
|
+
- test/asymmetric_encryptor_test.rb
|
82
83
|
- test/symmetric_encryptor_test.rb
|
83
|
-
- test/no_public_key_error_test.rb
|
84
|
-
- test/sha_encryptor_test.rb
|
85
84
|
- test/no_key_error_test.rb
|
85
|
+
- test/sha_encryptor_test.rb
|
86
|
+
- test/no_private_key_error_test.rb
|
86
87
|
- test/string_test.rb
|
87
|
-
- test/
|
88
|
+
- test/no_public_key_error_test.rb
|
88
89
|
- test/encryptor_test.rb
|
89
|
-
- test/no_private_key_error_test.rb
|
data/test/keys/encrypted_public
DELETED