Exemplo n.º 1
0
 public function keyTypeToIDE($val)
 {
     return my_base_convert($val, 36, 62);
 }
/**
 * decrypt an encrypted message or value
 * <br><br>Example:
 * <code>
 * <?php
 * $person_id = 12345;
 * $person_ide = encrypt($person_id,'person');
 * // $person_ide: iYq8okuGw9a
 * $temp = decrypt($person_ide,'person');
 * // $temp: 12345
 * ?>
 * </code>
 * @version 2.1
 * @param string $encrypted_message the encrypted message or value
 * @param string $key the private key, typically the name of the variable is used as the private key
 * @return string returns a decrypted message or false when unsuccessful
 * @see encrypt()
 */
function decrypt($encrypted_message, $key = 31337)
{
    global $sky_encryption_key;
    if (!$key) {
        $key = 31337;
    }
    //$key .= $sky_encryption_key;
    $temp = $key . $sky_encryption_key;
    if (strlen($temp) > 16) {
        $key = substr(strrev($key), 0, 16 - strlen($sky_encryption_key)) . $sky_encryption_key;
    } else {
        $key = $temp;
    }
    $encrypted_message = my_base_convert($encrypted_message, 62, 16);
    $encrypted_message = substr($encrypted_message, 1);
    $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $temp = trim(mcrypt_decrypt(MCRYPT_XTEA, $key, pack("H*", $encrypted_message), MCRYPT_MODE_ECB, $iv));
    if (ctype_alnum($temp)) {
        return $temp;
    } else {
        return false;
    }
}