/ Published in: PHP
Encryption class wrapper for Blowfish. Can be adapted to other encryption algorithms.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* * This class encapsulates Blowfish encryption and decryption. */ class Encrypter{ protected $key; protected $iv; function __construct($iv=null, $key=null){ $this->iv = $iv; } /** * Encrypts data * Returns binary data. */ function encrypt($data){ return $enc; } /** * Encrypts data and convert to hex. * Ideal for storing as text. */ function encryptToHex($data){ } /** * Takes hex input, convert from hex to binary then decrypt. */ function decryptFromHex($data){ //echo "hex \"$data\"\n"; return $this->decrypt($this->hex2bin($data)); } /** * */ function decrypt($data){ //echo "decode \"$decode\"\n"; //echo sprintf("[%s]\n", $realdata); return $realdata; } /** * Convert from binary to hex */ } /** * Convert from hex to binary */ function hex2bin($s){ } /** * loads key and iv from a file. * Key is on line 1 in hex. * IV is on line 2 in hex. */ function loadKeysFromFile($filename){ } /** * String is the key and the iv separates by a newline. * Use this when storing the key in a file. * Line 1 would be the key, line 2 is the iv. */ function loadKeysFromString($string){ $key = $keys[0]; $this->iv = $iv; } function showKeys(){ } } 4987bf894deh898efae46384efffeabcc387da8d7e8af893783745d1 4fecabab1234bcbc <?php require_once 'Encrypter.php'; class MyApp { public function run() { $e = new Encrypter; $e->loadKeysFromFile('keys'); echo $e->showKeys() . "\n"; $hex = $e->encryptToHex("4646123412341234"); print $hex . "\n"; print $e->decryptFromHex($hex) . "\n"; } } $app = new MyApp; $app->run();