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 CHANGED
@@ -1,5 +1,9 @@
1
1
  == master
2
2
 
3
+ == 0.3.2 / 2009-01-11
4
+
5
+ * Use Array#pack/String#unpack instead of Base64 to be compatible with Ruby 1.9+
6
+
3
7
  == 0.3.1 / 2008-12-4
4
8
 
5
9
  * Fix symmetric ciphers not working on Ruby 1.8.6 and below
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'encrypted_strings'
8
- s.version = '0.3.1'
8
+ s.version = '0.3.2'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Dead-simple string encryption/decryption syntax.'
11
11
 
@@ -1,3 +1,5 @@
1
+ require 'openssl'
2
+
1
3
  require 'encrypted_strings/extensions/string'
2
4
  require 'encrypted_strings/cipher'
3
5
  require 'encrypted_strings/symmetric_cipher'
@@ -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
- # * +private_key_file+ - Encrypted private key file
80
- # * +public_key_file+ - Public key file
81
- # * +password+ - The password to use in the symmetric cipher
82
- # * +algorithm+ - Algorithm to use symmetrically encrypted strings
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
- Base64.encode64(encrypted_data)
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 = Base64.decode64(data)
118
+ decrypted_data = data.unpack('m')[0]
119
119
  private_rsa.private_decrypt(decrypted_data)
120
120
  end
121
121
 
@@ -1,6 +1,3 @@
1
- require 'openssl'
2
- require 'base64'
3
-
4
1
  module EncryptedStrings
5
2
  module Extensions #:nodoc:
6
3
  # Adds support for in-place encryption/decryption of strings
@@ -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
- # * +salt+ - Random bytes used as one of the inputs for generating the encrypted string
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
- # * +algorithm+ - The algorithm to use for generating the encrypted string
64
- # * +password+ - The secret value to use for generating the key/initialization vector for the algorithm
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(Base64.decode64(data)) + cipher.final
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
- Base64.encode64(cipher.update(data) + cipher.final)
91
+ [cipher.update(data) + cipher.final].pack('m')
91
92
  end
92
93
 
93
94
  private
@@ -72,10 +72,11 @@ class ShaCipherWithNonStringSaltTest < Test::Unit::TestCase
72
72
  require 'time'
73
73
 
74
74
  def setup
75
- @sha_cipher = EncryptedStrings::ShaCipher.new(:salt => Time.parse('Tue Jan 01 00:00:00 UTC 2008'))
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 'Tue Jan 01 00:00:00 UTC 2008', @sha_cipher.salt
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.1
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: 2008-12-14 00:00:00 -05:00
12
+ date: 2009-01-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15