public
Description: All the extra stuff you could want for the Mack Framework.
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack-more.git
mack-more / mack-encryption / lib / mack-encryption / default_worker.rb
100644 28 lines (24 sloc) 0.967 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Mack
  module Utils # :nodoc:
    module Crypt # :nodoc:
      # The default worker is one that is used when no other worker is specified or the
      # specified worker does not exist. It uses the Crypt::Rijndael library and get's
      # it's secret key from app_config.default_secret_key
      class DefaultWorker
        
        def initialize
          @aes_key = ::Crypt::Rijndael.new(app_config.default_secret_key || (String.randomize(40)))
        end
        
        # Encrypts a string using the Crypt::Rijndael library and the secret key found in
        # app_config.default_secret_key
        def encrypt(x)
          @aes_key.encrypt_string(x)
        end
        
        # Decrypts a string using the Crypt::Rijndael library and the secret key found in
        # app_config.default_secret_key
        def decrypt(x)
          @aes_key.decrypt_string(x)
        end
        
      end # DefaultWorker
    end # Crypt
  end # Utils
end # Mack