encrypted_strings 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/Rakefile +1 -1
- data/lib/encrypted_strings.rb +2 -0
- data/lib/encrypted_strings/asymmetric_cipher.rb +6 -6
- data/lib/encrypted_strings/extensions/string.rb +0 -3
- data/lib/encrypted_strings/sha_cipher.rb +2 -1
- data/lib/encrypted_strings/symmetric_cipher.rb +5 -4
- data/test/sha_cipher_test.rb +3 -2
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
data/lib/encrypted_strings.rb
CHANGED
@@ -76,10 +76,10 @@ module EncryptedStrings
|
|
76
76
|
# Creates a new cipher that uses an asymmetric encryption strategy.
|
77
77
|
#
|
78
78
|
# Configuration options:
|
79
|
-
# *
|
80
|
-
# *
|
81
|
-
# *
|
82
|
-
# *
|
79
|
+
# * <tt>:private_key_file</tt> - Encrypted private key file
|
80
|
+
# * <tt>:public_key_file</tt> - Public key file
|
81
|
+
# * <tt>:password</tt> - The password to use in the symmetric cipher
|
82
|
+
# * <tt>:algorithm</tt> - Algorithm to use symmetrically encrypted strings
|
83
83
|
def initialize(options = {})
|
84
84
|
invalid_options = options.keys - [:private_key_file, :public_key_file, :algorithm, :password]
|
85
85
|
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
|
@@ -107,7 +107,7 @@ module EncryptedStrings
|
|
107
107
|
raise NoPublicKeyError, "Public key file: #{public_key_file}" unless public?
|
108
108
|
|
109
109
|
encrypted_data = public_rsa.public_encrypt(data)
|
110
|
-
|
110
|
+
[encrypted_data].pack('m')
|
111
111
|
end
|
112
112
|
|
113
113
|
# Decrypts the given data. If no private key file has been specified, then
|
@@ -115,7 +115,7 @@ module EncryptedStrings
|
|
115
115
|
def decrypt(data)
|
116
116
|
raise NoPrivateKeyError, "Private key file: #{private_key_file}" unless private?
|
117
117
|
|
118
|
-
decrypted_data =
|
118
|
+
decrypted_data = data.unpack('m')[0]
|
119
119
|
private_rsa.private_decrypt(decrypted_data)
|
120
120
|
end
|
121
121
|
|
@@ -41,7 +41,8 @@ module EncryptedStrings
|
|
41
41
|
# Creates a new cipher that uses an SHA encryption strategy.
|
42
42
|
#
|
43
43
|
# Configuration options:
|
44
|
-
# *
|
44
|
+
# * <tt>:salt</tt> - Random bytes used as one of the inputs for generating
|
45
|
+
# the encrypted string
|
45
46
|
def initialize(options = {})
|
46
47
|
invalid_options = options.keys - [:salt]
|
47
48
|
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
|
@@ -60,8 +60,9 @@ module EncryptedStrings
|
|
60
60
|
# Creates a new cipher that uses a symmetric encryption strategy.
|
61
61
|
#
|
62
62
|
# Configuration options:
|
63
|
-
# *
|
64
|
-
# *
|
63
|
+
# * <tt>:algorithm</tt> - The algorithm to use for generating the encrypted string
|
64
|
+
# * <tt>:password</tt> - The secret value to use for generating the
|
65
|
+
# key/initialization vector for the algorithm
|
65
66
|
def initialize(options = {})
|
66
67
|
invalid_options = options.keys - [:algorithm, :password]
|
67
68
|
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
|
@@ -81,13 +82,13 @@ module EncryptedStrings
|
|
81
82
|
# Decrypts the current string using the current key and algorithm specified
|
82
83
|
def decrypt(data)
|
83
84
|
cipher = build_cipher(:decrypt)
|
84
|
-
cipher.update(
|
85
|
+
cipher.update(data.unpack('m')[0]) + cipher.final
|
85
86
|
end
|
86
87
|
|
87
88
|
# Encrypts the current string using the current key and algorithm specified
|
88
89
|
def encrypt(data)
|
89
90
|
cipher = build_cipher(:encrypt)
|
90
|
-
|
91
|
+
[cipher.update(data) + cipher.final].pack('m')
|
91
92
|
end
|
92
93
|
|
93
94
|
private
|
data/test/sha_cipher_test.rb
CHANGED
@@ -72,10 +72,11 @@ class ShaCipherWithNonStringSaltTest < Test::Unit::TestCase
|
|
72
72
|
require 'time'
|
73
73
|
|
74
74
|
def setup
|
75
|
-
@
|
75
|
+
@time = Time.parse('Tue Jan 01 00:00:00 UTC 2008')
|
76
|
+
@sha_cipher = EncryptedStrings::ShaCipher.new(:salt => @time)
|
76
77
|
end
|
77
78
|
|
78
79
|
def test_should_stringify_salt
|
79
|
-
assert_equal
|
80
|
+
assert_equal @time.to_s, @sha_cipher.salt
|
80
81
|
end
|
81
82
|
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.3.
|
4
|
+
version: 0.3.2
|
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:
|
12
|
+
date: 2009-01-11 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|