private function generarValidacionXML($xml, $version = 2) { $version = $version == null ? 2 : $version; $pos = strrpos($xml, "</"); $xml1 .= "<validacion>"; $xml1 .= "<version>{$version}</version>"; $xml1 .= "</validacion>"; $xml = substr_replace($xml, $xml1, $pos, 0); $key = md5("RoKoPo999ADS897"); $iv = "dasdREWTRB5454gt"; $AES = new AES_Encryption($key, $iv); $validacionTag = $AES->encrypt($xml); $char = ''; for ($i = 0; $i < strlen($validacionTag); $i++) { $caracter = "00" . dechex(ord(substr($validacionTag, $i, 1))); $char .= substr($caracter, strlen($caracter) - 2); } $pos = strpos($xml, "</validacion>"); $xml = substr_replace($xml, "<codigo>{$char}</codigo>", $pos, 0); return $xml; }
function aesDecrypt($data, $encode = 'url') { if ($data == CPropertyValue::ensureInteger($data) . '') { //xmail('Decrypting data which is not encrypted', app()->request->requestUri, SETTINGS_DEV_EMAILS); return $data; } $key = hasParam('SETTINGS_AES_ENCRYPT_IV', 'aninditioncmskey'); Yii::import('Xpress.extensions.vendors.encryption.AES_Encryption'); $aes = new AES_Encryption(hasParam('SETTINGS_AES_ENCRYPT_KEY', '5682825638385896'), $key); switch ($encode) { case 'url': $data = base64_decode(strtr($data, array('-' => '+', '_' => '/'))); break; case 'base64': $data = base64_decode($data); break; } return $aes->decrypt($data); }
/** * Encrypt an email address with AES cbc PKCS7 using 16 byte iv * * @since v1.0 * * @param $email string plain text email address * * @return string hex encrypted email */ private function encrypt_email($email) { require_once 'includes/padCrypt.php'; require_once 'includes/AES_Encryption.php'; $apisecret = get_option('skey'); $apisecret_utf8 = utf8_encode($apisecret); $apisecret_seg = substr($apisecret_utf8, 0, 16); $iv = str_repeat("", 16); $mode = "cbc"; $padding = "PKCS7"; $AES = new AES_Encryption($apisecret_seg, $iv, $padding, $mode); $encrypted = $AES->encrypt($email); $hex = bin2hex($encrypted); return $hex; }
/** * Decrypt a value encyrpted using AES 256 encryption in CBC mode. * * @param string $value Value to be decrypted * @return string Decrypted value. */ public function decrypt($value) { $AES = new AES_Encryption($this->algorithm_key, $this->algorithm_iv); return $AES->decrypt(base64_decode($value)); }