views:

49

answers:

2

because of gfw(great firewall) in our country , I have to encode content within http transfer (https is better , but its a second choice).

my way is use base64 encode by php and decode by js , then show in an iframe. but there's some problem in FF.

is there any better way to show base64 encoded string in browser , or another way to encode/decode ?

A: 
Try Something this:

    function get_rnd_iv($iv_len)
    {
        $iv = '';
        while ($iv_len-- > 0) {
            $iv .= chr(mt_rand() & 0xff);
        }
        return $iv;
    }

    function md5_encrypt($string_value, $salt_key, $iv_len = 16)
    {
        $string_value .= "\x13";
        $n = strlen($string_value);
        if ($n % 16) $string_value .= str_repeat("\0", 16 - ($n % 16));
        $i = 0;
        $enc_text = get_rnd_iv($iv_len);
        $iv = substr($salt_key ^ $enc_text, 0, 512);
        while ($i < $n) {
            $block = substr($string_value, $i, 8) ^ pack('H*', md5($iv));
            $enc_text .= $block;
            $iv = substr($block . $iv, 0, 512) ^ $salt_key;
            $i += 16;
        }
        return urlencode(base64_encode($enc_text));
    }

    function md5_decrypt($enc_text, $salt_key, $iv_len = 16)
    {
        $enc_text = urldecode(base64_decode($enc_text));
        $n = strlen($enc_text);
        $i = $iv_len;
        $string_value = '';
        $iv = substr($salt_key ^ substr($enc_text, 0, $iv_len), 0, 512);
        while ($i < $n) {
            $block = substr($enc_text, $i, 8);
            $string_value .= $block ^ pack('H*', md5($iv));
            $iv = substr($block . $iv, 0, 512) ^ $salt_key;
            $i += 16;
        }
        return preg_replace('/\\x13\\x00*$/', '', $string_value);
    }
Joe Garrett
I really hope that these functions are wildly mislabeled, as MD5 doesn't encrypt, and isn't reversible, because it is a hash function.
You
true they are a hash function...I'm using them to encode my values that are passed in of course...and then doing a base64 encode. Of course also the reverse to decrypt them. For the purpose of obscuring the data.
Joe Garrett
A: 

You could just set the innerHTML property of the body of the page...

As long as the encoded string that the JS is producing is valid HTML for the whole body, it should work fine, and then you don't have to do anything messy with iframes or whatever.

zebediah49
yeah, it's a way , I think it will work
lzyy