Sha256: 7d570f6968cdd3be272075611c59027d4a11a161a6ec74864d1e9c216e1896b1

Contents?: true

Size: 935 Bytes

Versions: 32

Compression:

Stored size: 935 Bytes

Contents

module TwitterAuth
  module Cryptify
    class Error < StandardError; end
    
    def self.encrypt(data)
      salt = generate_salt
      {:encrypted_data => EzCrypto::Key.encrypt_with_password(TwitterAuth.encryption_key, salt, data), :salt => salt}
    end
 
    def self.decrypt(encrypted_data_or_hash, salt=nil)
      case encrypted_data_or_hash
      when String
        encrypted_data = encrypted_data_or_hash
        raise ArgumentError, 'Must provide a salt to decrypt.' unless salt
      when Hash
        encrypted_data = encrypted_data_or_hash[:encrypted_data]
        salt = encrypted_data_or_hash[:salt]
      else
        raise ArgumentError, 'Must provide either an encrypted hash result or encrypted string and salt.'
      end

      EzCrypto::Key.decrypt_with_password(TwitterAuth.encryption_key, salt, encrypted_data)
    end
  
    def self.generate_salt
      ActiveSupport::SecureRandom.hex(4)
    end
  end
end

Version data entries

32 entries across 32 versions & 4 rubygems

Version Path
mbleigh-twitter-auth-0.1.1 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.10 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.11 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.12 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.13 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.14 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.15 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.16 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.18 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.20 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.21 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.22 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.3 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.5 lib/twitter_auth/cryptify.rb
mbleigh-twitter-auth-0.1.8 lib/twitter_auth/cryptify.rb
millsb-twitter-auth-0.1.16 lib/twitter_auth/cryptify.rb
xaviershay-twitter-auth-0.1.19 lib/twitter_auth/cryptify.rb
twitter-auth-0.1.22 lib/twitter_auth/cryptify.rb
twitter-auth-0.1.10 lib/twitter_auth/cryptify.rb
twitter-auth-0.1.12 lib/twitter_auth/cryptify.rb