Sha256: 946f625357c8ee7eaa01fdc579913007bb67ed91c8cb0f42fba30f5f9c343f0d

Contents?: true

Size: 1015 Bytes

Versions: 19

Compression:

Stored size: 1015 Bytes

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 and algorithm 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

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
padrino-admin-0.9.6 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.5 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.4 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.3 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.2 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.1 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.9.0 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.8.5 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.8.4 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.8.3 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.8.2 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.8.1 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.8.0 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.7.9 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.7.8 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.7.7 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.7.6 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.7.5 lib/padrino-admin/utils/crypt.rb
padrino-admin-0.7.4 lib/padrino-admin/utils/crypt.rb