File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11== master
22
3+ * Use pack/unpack instead of Base64 to be compatible with Ruby 1.9+
4+
35== 0.3.1 / 2008-12-4
46
57* Fix symmetric ciphers not working on Ruby 1.8.6 and below
Original file line number Diff line number Diff line change 1+ require 'openssl'
2+
13require 'encrypted_strings/extensions/string'
24require 'encrypted_strings/cipher'
35require 'encrypted_strings/symmetric_cipher'
Original file line number Diff line number Diff line change @@ -107,15 +107,15 @@ def encrypt(data)
107107 raise NoPublicKeyError , "Public key file: #{ public_key_file } " unless public?
108108
109109 encrypted_data = public_rsa . public_encrypt ( data )
110- Base64 . encode64 ( encrypted_data )
110+ [ encrypted_data ] . pack ( 'm' )
111111 end
112112
113113 # Decrypts the given data. If no private key file has been specified, then
114114 # a NoPrivateKeyError will be raised.
115115 def decrypt ( data )
116116 raise NoPrivateKeyError , "Private key file: #{ private_key_file } " unless private?
117117
118- decrypted_data = Base64 . decode64 ( data )
118+ decrypted_data = data . unpack ( 'm' ) [ 0 ]
119119 private_rsa . private_decrypt ( decrypted_data )
120120 end
121121
Original file line number Diff line number Diff line change 1- require 'openssl'
2- require 'base64'
3-
41module EncryptedStrings
52 module Extensions #:nodoc:
63 # Adds support for in-place encryption/decryption of strings
Original file line number Diff line number Diff line change @@ -81,13 +81,13 @@ def initialize(options = {})
8181 # Decrypts the current string using the current key and algorithm specified
8282 def decrypt ( data )
8383 cipher = build_cipher ( :decrypt )
84- cipher . update ( Base64 . decode64 ( data ) ) + cipher . final
84+ cipher . update ( data . unpack ( 'm' ) [ 0 ] ) + cipher . final
8585 end
8686
8787 # Encrypts the current string using the current key and algorithm specified
8888 def encrypt ( data )
8989 cipher = build_cipher ( :encrypt )
90- Base64 . encode64 ( cipher . update ( data ) + cipher . final )
90+ [ cipher . update ( data ) + cipher . final ] . pack ( 'm' )
9191 end
9292
9393 private
Original file line number Diff line number Diff line change @@ -72,10 +72,11 @@ class ShaCipherWithNonStringSaltTest < Test::Unit::TestCase
7272 require 'time'
7373
7474 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 )
7677 end
7778
7879 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
8081 end
8182end
You can’t perform that action at this time.
0 commit comments