Published in: PHP
URL: http://www.mechanicmatt.com
<?php class class_crypt { var $algorithms = NULL; var $mode = NULL; var $key = NULL; var $algorithm = NULL; var $iv = NULL; var $iv_size = NULL; function __construct() { $this->crypt(); } MCRYPT_3DES, MCRYPT_BLOWFISH, MCRYPT_CAST_256, MCRYPT_GOST, MCRYPT_LOKI97, MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_192, MCRYPT_RIJNDAEL_256, MCRYPT_RC2, MCRYPT_SAFERPLUS, MCRYPT_SERPENT, MCRYPT_TRIPLEDES, MCRYPT_TWOFISH, "xor" ); $this->algorithm = MCRYPT_CAST_256; $this->mode = MCRYPT_MODE_NOFB; $this->key = ($key != "") ? $key : "JF^#@&*973LSD38)(@#&_9&@#*"; if ($this->algorithm == "") { $this->algorithm = $this->algorithms[13]; } else {} $this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode); $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND); } function set_key($key) { $this->key = $key; } function encrypt($data, $iv_len = 16) { switch($this->algorithm) { case "xor": $data .= "\x13"; if ($n % 16) { $i = 0; $data = $this->get_rnd_iv($iv_len); while ($i < $n) { $data .= $block; $i += 16; } } else {} break; default: return mcrypt_encrypt($this->algorithm, $this->key, $data, $this->mode, $this->iv); break; } } function decrypt($data, $iv_len = 16) { switch($this->algorithm) { case "xor": $i = $iv_len; $plain_text = ''; while ($i < $n) { $i += 16; } break; default: return mcrypt_decrypt($this->algorithm, $this->key, $data, $this->mode, $this->iv); break; } } } $crypt = new class_crypt(13, "Your Secret Private Key"); $crypt->encrypt("raw data to encrypt"); $crypt->decrypt("encrypted data to decrypt"); ?>
You need to login to post a comment.
