Module: Senv::Blowfish

Extended by:
Blowfish
Included in:
Blowfish
Defined in:
lib/senv.rb

Instance Method Summary collapse

Instance Method Details

#cipher(senv, key, data) ⇒ Object



518
519
520
521
522
# File 'lib/senv.rb', line 518

def cipher(senv, key, data)
  cipher = OpenSSL::Cipher.new('bf-cbc').send(senv)
  cipher.key = Digest::SHA256.digest(key.to_s).slice(0,16)
  cipher.update(data) << cipher.final
end

#cycle(key, data) ⇒ Object



532
533
534
# File 'lib/senv.rb', line 532

def cycle(key, data)
  decrypt(key, encrypt(key, data))
end

#decrypt(key, text) ⇒ Object



528
529
530
# File 'lib/senv.rb', line 528

def decrypt(key, text)
  cipher(:decrypt, key, text)
end

#encrypt(key, data) ⇒ Object



524
525
526
# File 'lib/senv.rb', line 524

def encrypt(key, data)
  cipher(:encrypt, key, data)
end

#recrypt(old_key, new_key, data) ⇒ Object



536
537
538
# File 'lib/senv.rb', line 536

def recrypt(old_key, new_key, data)
  encrypt(new_key, decrypt(old_key, data))
end