/* Global.php 通用函数,调用RSA类提供加密解密功能。 云舒 , 2007年10月1日 */ function encrypt( $plain_text ) { $public_key = 'YTozOntpOjA7czozMjoiS1vW5NNLH39farB+HPE/U0A1fs1I7ja81GJxGrrjsYEiO2k6MTtzOjM6IgEAASI7aToyO3M 6NjoicHVibGljIjt9'; $key = Crypt_RSA_Key::fromString($public_key); check_error($key); $rsa_obj = new Crypt_RSA; check_error($rsa_obj); $enc_text = $rsa_obj->encrypt($plain_text, $key); check_error($rsa_obj); return $enc_text; } function decrypt( $enc_text ) { $private_key = "YTozOntpOjA7czozMjoiS1vW5NNLH39farB+HPE/U0A1fs1I7ja81GJxGrrjsYEiO2k6MTtzOjMyOiIButTavL72eeX VEa8E5WkAJthoHqmHIyo3HblsSJG0aiI7aToyO3M6NzoicHJpdmF0ZSI7fQ=="; $key = Crypt_RSA_Key::fromString($private_key); check_error($key); $rsa_obj = new Crypt_RSA; check_error($rsa_obj); $rsa_obj->setParams(array('dec_key' => $key)); check_error($rsa_obj); $number = $rsa_obj->decrypt($enc_text); return $number; } |
/* 水印需求方,随机生成字符串,然后加密发送给水印生成方 云舒 , 2007年10月1日 */ require_once 'Global.php'; $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $str_a = $chars{mt_rand(0,35)}; $str_b = $chars{mt_rand(0,35)}; $str_c = $chars{mt_rand(0,35)}; $str_d = $chars{mt_rand(0,35)}; $str = $str_a.$str_b.$str_c.$str_d; $enc_data = encrypt( $str ); echo '<html><head><title>test</title></head><body><img src="CreateImg.php?number=' .rawurlencode( $enc_data ). '" /></body></html>'; |
/* 水印提供方,获取需求方传递过来的参数,解密,画出图形 云舒 , 2007年10月1日 */ require_once 'Global.php'; header('Content-type: image/gif'); if( isset( $_GET["number"] ) ) { $enc_number = rawurldecode( $_GET["number"] ); } else { exit; } $de_number = decrypt( $enc_number ); $chars = preg_split( '//', $de_number ); $im = imagecreate(75,30); $bg = imagecolorallocate($im, 255, 255, 255);//背景 $font_color = imagecolorallocate($im, 0, 0, 0);//字 imagestring($im, mt_rand(5,9), mt_rand(0,5), mt_rand(0,5), $chars[1], $font_color); imagestring($im, mt_rand(5,9), mt_rand(15,25), mt_rand(0,5), $chars[2], $font_color); imagestring($im, mt_rand(5,9), mt_rand(30,40), mt_rand(0,5), $chars[3], $font_color); imagestring($im, mt_rand(5,9), mt_rand(45,50), mt_rand(0,5), $chars[4], $font_color); // 随机点 for ($i=1; $i<=10; $i++) { imagestring($im,mt_rand(0,5),mt_rand(-5,63),mt_rand(-5,23),".",imageColorAllocate ($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255))); } imagegif($im); imagedestroy ($im); |
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/) | Powered by Discuz! 7.2 |