Jump to content

Convert Unicode value to ASCII value for use in Query


rocafreestyler

Recommended Posts

function NC_DecryptString($key, $encryptedString)  
{  
    // is the mcrypt extension installed?  
    if (!extension_loaded('mcrypt'))  
    { 
        return false;  
    } 

    // first, convert the HEX-Encoded string to real characters  
    $deHexedString = "";  
    $originalStringLength = strlen($encryptedString);  
    if (($originalStringLength % 2) != 0)  
    {  
        return false;  
    }  

    for ($i = 0 ; $i < $originalStringLength ; $i += 2)  
    {  
        list($value) = sscanf(substr($encryptedString, $i, 2), "%x");  

        $deHexedString .= chr($value);  
    }  

    // make sure the key isn't too long;  
    $key = substr($key, 0, 56);  

    // prepare to decrypt  
    $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');  
    $iv = str_repeat(chr(0), ;  
    mcrypt_generic_init($td, $key, $iv);  

    // decrypt the data  
    return mdecrypt_generic($td, $deHexedString);  
}  
// Test decrypting data. 
$s = NC_DecryptString("Some magic key", "DA3111ED52E51A3E8A0AA734C833799D7074730274D9F8C6A561423CC9AB2C7C");  
if ($s !== false)  
{  
    echo $s . '<br>'; 
    echo 'Length: ' . strlen($s) . '<br>'; 
    for ($i = 0 ; $i < strlen($s) ; $i++) 
    { 
        echo ord($s[$i]) . '  ';  
    } 
}  
else  
{  
    echo "There was a failure.";  
}   

echo '<hr>';

 

The output of NC_DecryptString is Unicode.

 

I think the reason that it is not working is because of null values in the string that I need to strip out.

 

So the value i receive back from this function does not work in my mySQL query, but if I save the string it appears correct but if I do a strLen on it it is over double the length I would expect

 

Cheers

 

Cheers

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.