Sha256: ee37c4fd4509490c7dfdc1dd2638ee68b18af08a606cc6bb4cdce22d63be284c
Contents?: true
Size: 680 Bytes
Versions: 1
Compression:
Stored size: 680 Bytes
Contents
module Refcode class Encoder attr_accessor :secret, :salt def initialize yield self if block_given? end def encode val Base64URL.encode(encrypt(YAML.dump(val))) end def decode val YAML.load(decrypt(Base64URL.decode(val))) end def secret= secret secret = secret * 2 until secret.size >= 32 @secret = secret end private def encrypt val Encryptor.encrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv) end def decrypt val Encryptor.decrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv) end def iv [@secret, @salt, 42].join end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
refcode-0.1.2 | lib/refcode/encoder.rb |