Sha256: f22d1cb9f6d5f3cb6cfe9e6661ce52b150ceabf80a90dd9a263ce3d89d85fde2

Contents?: true

Size: 1.07 KB

Versions: 24

Compression:

Stored size: 1.07 KB

Contents

require 'openssl'

module Padrino
  module Admin
    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) #:nodoc:
          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

24 entries across 24 versions & 1 rubygems

Version Path
padrino-admin-0.10.1 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.10.0 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.29 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.28 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.27 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.26 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.24 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.25 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.23 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.22 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.21 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.20 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.19 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.18 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.17 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.16 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.15 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.14 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.13 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.12 lib/padrino-admin/utils/crypt.rb