Skip to content
Extraits de code Groupes Projets
Valider ce9c17fa rédigé par danielgrippi's avatar danielgrippi Validation de Ilya Zhitomirskiy
Parcourir les fichiers

use ActiveSupport's Base64 encoding methods instead of calling Array#pack...

use ActiveSupport's Base64 encoding methods instead of calling Array#pack directly; strip new lines.
parent 36f5e45c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -16,7 +16,7 @@ module Encryptor
cipher = OpenSSL::Cipher.new('AES-256-CBC')
key = cipher.random_key
iv = cipher.random_iv
{'key' => Base64.encode64s(key), 'iv' => Base64.encode64(iv)}
{'key' => Base64.encode64s(key), 'iv' => Base64.encode64s(iv)}
end
def aes_encrypt(txt, key)
......
......@@ -5,28 +5,12 @@
# Add URL safe Base64 support
module Base64
module_function
# Returns the Base64-encoded version of +bin+.
# This method complies with RFC 4648.
# No line feeds are added.
def strict_encode64(bin)
[bin].pack("m0")
end
# Returns the Base64-decoded version of +str+.
# This method complies with RFC 4648.
# ArgumentError is raised if +str+ is incorrectly padded or contains
# non-alphabet characters. Note that CR or LF are also rejected.
def strict_decode64(str)
Rails.logger.info("trying to decode string: " + str)
str.unpack("m0").first
end
# Returns the Base64-encoded version of +bin+.
# This method complies with ``Base 64 Encoding with URL and Filename Safe
# Alphabet'' in RFC 4648.
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
def urlsafe_encode64(bin)
strict_encode64(bin).tr("+/", "-_")
self.encode64s(bin).tr("+/", "-_")
end
# Returns the Base64-decoded version of +str+.
......@@ -34,7 +18,7 @@ module Base64
# Alphabet'' in RFC 4648.
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
def urlsafe_decode64(str)
strict_decode64(str.tr("-_", "+/"))
self.decode64(str.tr("-_", "+/"))
end
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter