Sha256: 3d34a5c51106fd6e8db8a3635646da92e34da63986b29124049231848e46d898

Contents?: true

Size: 663 Bytes

Versions: 20

Compression:

Stored size: 663 Bytes

Contents

module TarvitHelpers
  class SimpleCrypt
    require 'openssl'
    require 'digest/sha1'
    require 'base64'

    TYPE = "aes-256-cbc"

    def initialize(secret_key)
      @ciper = OpenSSL::Cipher::Cipher.new(TYPE)
      @secret_key = secret_key.to_s
    end

    def encrypt(string)
      @ciper.encrypt
      @ciper.key = Digest::SHA1.hexdigest(@secret_key)
      res = @ciper.update(string)
      res << @ciper.final
      Base64.encode64(res)
    end

    def decrypt(code)
      hash = Base64.decode64(code)
      @ciper.decrypt
      @ciper.key = Digest::SHA1.hexdigest(@secret_key)
      d = @ciper.update(hash)
      d << @ciper.final
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
tarvit-helpers-0.0.23 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.22 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.21 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.20 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.19 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.18 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.17 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.16 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.15 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.14 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.13 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.12 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.11 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.10 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.9 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.8 lib/tarvit-helpers/modules/simple_crypt.rb
tarvit-helpers-0.0.6 lib/modules/simple_crypt.rb
tarvit-helpers-0.0.5 lib/modules/simple_crypt.rb
tarvit-helpers-0.0.4 lib/modules/simple_crypt.rb
tarvit-helpers-0.0.3 lib/modules/simple_crypt.rb