Sha256: ffcb235266b0bf75a6d8c9afd07b584a52b0a8b4028d26b395ef64ba1a319d61

Contents?: true

Size: 1.15 KB

Versions: 13

Compression:

Stored size: 1.15 KB

Contents

require 'openssl'

module Padrino
  module Admin
    ##
    # Common utility methods used within the admin application.
    #
    module Utils
      ##
      # This util it's used for encrypt/decrypt password.
      # We want password decryptable because generally for our sites we have: password_lost.
      # We prefer send original password instead reset them.
      #
      module Crypt
        ##
        # Decrypts the current string using the current key specified
        #
        def decrypt(password)
          cipher = build_cipher(:decrypt, password)
          cipher.update(self.unpack('m')[0]) + cipher.final
        end

        ##
        # Encrypts the current string using the current key and algorithm specified
        #
        def encrypt(password)
          cipher = build_cipher(:encrypt, password)
          [cipher.update(self) + cipher.final].pack('m').chomp
        end

      private
        def build_cipher(type, password) # @private
          cipher = OpenSSL::Cipher::Cipher.new("DES-EDE3-CBC").send(type)
          cipher.pkcs5_keyivgen(password)
          cipher
        end
      end # Crypt
    end # Utils
  end # Admin
end # Padrino

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
padrino-admin-0.11.3 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.11.2 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.11.1 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.11.0 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.7 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.6 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.6.e lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.6.d lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.6.c lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.6.b lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.6.a lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.5 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.4 lib/padrino-admin/utils/crypt.rb