HTTP PUT方法实例

1.test.php:

1), true);
$pwd = 'my_key';
$encrypted_data = $rc4->encrypt($pwd, $data);
$return = curl_request($url, base64_encode($encrypted_data), 'PUT');
var_dump($return);

data.php:

 $val) {
		$data = $key;
	}
	
	$rc4 = new rc4crypt();
	$pwd = 'mykey';
	$encryted_data = base64_decode($data);
	
	$json_data = $rc4->decrypt($pwd, $encryted_data);
	
	$data = json_decode($json_data, true);
	
	//print_r($data);
	
	$id = $data['id'];
	echo $id;
}

RC4.php:


         * @version $Id: class.rc4crypt.php,v 3.2 2006/03/10 05:47:24 mukul Exp                                            $
         * @copyright Copyright © 2006 Mukul Sabharwal
         * @license http://www.gnu.org/copyleft/gpl.html
         * @package RC4Crypt
         */

        /**
         * RC4 Class
         * @package RC4Crypt
         */
        class rc4crypt {
                /**
                 * The symmetric encryption function
                 *
                 * @param string $pwd Key to encrypt with (can be binary of hex)
                 * @param string $data Content to be encrypted
                 * @param bool $ispwdHex Key passed is in hexadecimal or not
                 * @access public
                 * @return string
                 */
                static function encrypt ($pwd, $data, $ispwdHex = 0)
                {
                        if ($ispwdHex)
                                $pwd = @pack('H*', $pwd); // valid input, please                                           !

                        $key[] = '';
                        $box[] = '';
                        $cipher = '';

                        $pwd_length = strlen($pwd);
                        $data_length = strlen($data);

                        for ($i = 0; $i < 256; $i++)
                        {
                                $key[$i] = ord($pwd[$i % $pwd_length]);
                                $box[$i] = $i;
                        }
                        for ($j = $i = 0; $i < 256; $i++)
                        {
                                $j = ($j + $box[$i] + $key[$i]) % 256;
                                $tmp = $box[$i];
                                $box[$i] = $box[$j];
                                $box[$j] = $tmp;
                        }
                        for ($a = $j = $i = 0; $i < $data_length; $i++)
                        {
                                $a = ($a + 1) % 256;
                                $j = ($j + $box[$a]) % 256;
                                $tmp = $box[$a];
                                $box[$a] = $box[$j];
                                $box[$j] = $tmp;
                                $k = $box[(($box[$a] + $box[$j]) % 256)];
                                $cipher .= chr(ord($data[$i]) ^ $k);
                        }
                        return $cipher;
                }
                /**
                 * Decryption, recall encryption
                 *
                 * @param string $pwd Key to decrypt with (can be binary of hex)
                 * @param string $data Content to be decrypted
                 * @param bool $ispwdHex Key passed is in hexadecimal or not
                 * @access public
                 * @return string
                 */
                static function decrypt ($pwd, $data, $ispwdHex = 0)
                {
                        return rc4crypt::encrypt($pwd, $data, $ispwdHex);
                }
        }
?>


你可能感兴趣的:(php)