function decrypt($input, $key)
{
    // Split the input into its parts
    $cipherSplit = explode(" ", $input);
    $originalSize = intval($cipherSplit[0]);
    $iv = cryptoHelpers::toNumbers($cipherSplit[1]);
    $cipherText = $cipherSplit[2];
    // Set up encryption parameters
    $cipherIn = cryptoHelpers::toNumbers($cipherText);
    $keyAsNumbers = cryptoHelpers::toNumbers(bin2hex($key));
    $keyLength = count($keyAsNumbers);
    $decrypted = AES::decrypt($cipherIn, $originalSize, AES::modeOfOperation_CBC, $keyAsNumbers, $keyLength, $iv);
    // Byte-array to text.
    $hexDecrypted = cryptoHelpers::toHex($decrypted);
    $retVal = pack("H*", $hexDecrypted);
    return $retVal;
}
Example #2
0
function wplc_decrypt_msg($input)
{
    $messages = maybe_unserialize($input);
    if (is_array($messages)) {
        if ($messages['e'] == 1) {
            /* This message was encrypted */
            $api_key = get_option('wplc_api_key');
            $api_key = substr($api_key, 0, 10);
            $cipherSplit = explode(" ", $messages['m']);
            $originalSize = intval($cipherSplit[0]);
            $iv = cryptoHelpers::toNumbers($cipherSplit[1]);
            $cipherText = $cipherSplit[2];
            $cipherIn = cryptoHelpers::toNumbers($cipherText);
            $keyAsNumbers = cryptoHelpers::toNumbers(bin2hex($api_key));
            $keyLength = count($keyAsNumbers);
            $decrypted = AES::decrypt($cipherIn, $originalSize, AES::modeOfOperation_CBC, $keyAsNumbers, $keyLength, $iv);
            $hexDecrypted = cryptoHelpers::toHex($decrypted);
            $retVal = pack("H*", $hexDecrypted);
            return stripslashes($retVal);
        } else {
            return stripslashes($messages['m']);
        }
    } else {
        return stripslashes($input);
    }
}
Example #3
0
    {
        $byteArray = array();
        for ($i = 0; $i < strlen($s); $i++) {
            $byteArray[] = ord($s[$i]);
        }
        return $byteArray;
    }
    public static function convertByteArrayToString($byteArray)
    {
        $s = '';
        for ($i = 0; $i < count($byteArray); $i++) {
            $s .= chr($byteArray[$i]);
        }
        return $s;
    }
    public static function base64_encode_line($b)
    {
        return base64_encode(self::convertByteArrayToString($b));
    }
    public static function base64_encode($b)
    {
        $b64 = self::base64_encode_line($b);
        return chunk_split($b, 64, "\n");
    }
    public static function base64_decode($b)
    {
        return self::convertStringToByteArray(base64_decode($b));
    }
}
var_dump(cryptoHelpers::base64_decode('BBB'));