lib/symmetric_encryption/symmetric_encryption.rb in symmetric-encryption-0.9.1 vs lib/symmetric_encryption/symmetric_encryption.rb in symmetric-encryption-1.0.0
- old
+ new
@@ -64,16 +64,11 @@
# the supplied key and iv
#
def self.decrypt(str)
raise "Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data" unless @@cipher
- # Decode data first based on encoding setting
- case @@cipher.encoding
- when :base64, :base64strict
- str = ::Base64.decode64(str) if str
- end
-
+ # Decode and then decrypt supplied string
begin
@@cipher.decrypt(str)
rescue OpenSSL::Cipher::CipherError => exc
@@secondary_ciphers.each do |cipher|
begin
@@ -90,22 +85,11 @@
# Returns nil if the supplied str is nil
# Returns "" if it is a string and it is empty
def self.encrypt(str)
raise "Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data" unless @@cipher
- # Encrypt data as a binary string
- if result = @@cipher.encrypt(str)
- # Now encode data based on encoding setting
- case @@cipher.encoding
- when :base64
- # Base 64 Encoding of binary data
- ::Base64.encode64(result)
- when :base64strict
- ::Base64.encode64(result).gsub(/\n/, '')
- else
- result
- end
- end
+ # Encrypt and then encode the supplied string
+ @@cipher.encrypt(str)
end
# Invokes decrypt
# Returns decrypted String
# Return nil if it fails to decrypt a String
\ No newline at end of file