1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
<?php
include_once('../phpseclib0.3.6/Crypt/RSA.php');
$rsa = new Crypt_RSA();
$public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDH0i//hwmPSCUNAS9UiD3wSH43 NxwRKwGtHQKGarANuYNacSXb+rS2N0WKihz+aSkevePj5GZPtu21Fpx0Tt541DBl UrYL0vPK4S6QUX8I5vsOQ/XuIyh9NKcD2fbmf/1QrC+q7pv6xa6ctaV8u1RPGI7C AIPtMCrh9Pbg+EFo0wIDAQAB";
$rsa->loadKey($public_key); // public key
$plaintext = "qwerty123-+%$*%^@#$%";
//$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP); $ciphertext = base64_encode($rsa->encrypt($plaintext));
var_dump($ciphertext);
$private_key = "MIICXAIBAAKBgQDH0i//hwmPSCUNAS9UiD3wSH43NxwRKwGtHQKGarANuYNacSXb +rS2N0WKihz+aSkevePj5GZPtu21Fpx0Tt541DBlUrYL0vPK4S6QUX8I5vsOQ/Xu Iyh9NKcD2fbmf/1QrC+q7pv6xa6ctaV8u1RPGI7CAIPtMCrh9Pbg+EFo0wIDAQAB AoGATSi2HRMtV1UR7YggGSG03SR5DGQs49o5/vldQL9QtTQF6zYW2u9fuZ71LO5x DLJZzQOhTJ4k/bIS7yLIjkboM4x75DlRpG14Umi+d2GePB+r9UiqeZ67Zh7OvKFU 1CIkNC2J9G0U2G4RSG2UAZKkimIofmptq7dXa5oYYNL74t0CQQDi4RHoxIhqh9mw rLxvawgcq6gseKuY5zEgJMHGtNQTIGqn1LgxCCwNx5473xc7jW6GQbgCtDVwGqeb VkejSSsFAkEA4XgGfrAFHSQdZ9+GkNsT+eZioX5wyxP78b3csTRPPii4NudJmyeu yHmmhhJV6fknQ9ZsYqLwHH3gJpzXeH/79wJAEL3S+H4oItRLeAIHFaGsQ5FXI5Dz +KB2u4x60BLf41ltBV1pChU0SwAD6R8ZM8fH9Bg9X9W0a8VLwOao+p+XkQJBANG3 MGNaGgeW9fsOAD5wZ85Dqm4IC6X4upmKPeJdg2+PtHjs/Jvid0JlVKzUFTGB3DHP GhVM9QWrV3jS3eBpOtUCQB6Fyf7bkMHxRwa2QLoB3bM/gvk0mJPCBFpILfI5RZZG XezjDt3Xo/MqppBr8nybC42OxjbID9ALPPe/VX9AVmA=";
$rsa->loadKey($private_key); // private key echo $rsa->decrypt(base64_decode($ciphertext));
exit; //$rsa->decrypt(base64_decode($row2{"test1"}));
//new pdo if (!headers_sent()) { header('X-UA-Compatible: IE=8,chrome=1'); }
//$dbh = new PDO("mysql:host=localhost;dbname=eizocomcn_db", "eixocomcnsa", "2E39enc3"); //$dbh->exec("set names utf8");
date_default_timezone_set("Asia/Hong_Kong");
if (!function_exists('random_string')) { function random_string( $length = 8 ) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $random_string = substr( str_shuffle( $chars ), 0, $length ); return $random_string; } }
if (session_id() === "") { session_start(); }
error_reporting(E_ALL); ini_set('display_errors', 1);
/*$sql = "insert into test (test1) values (?)"; if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute(array($ciphertext))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }*/
$dbh = mysql_connect("localhost", "eixocomcnsa", "2E39enc3");
if (!$dbh) { die('Could not connect: ' . mysql_error()); } $selected = mysql_select_db("eizocomcn_db",$dbh) or die("Could not select first_test");
mysql_query("SET NAMES UTF8");
if (!function_exists('check_input')) { function check_input($value) { if(!empty($value)){ // 去除斜杠 if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // 如果不是?字?加引号
$value = mysql_real_escape_string(htmlspecialchars($value)) ;
return $value; }else{ return $value; } } }
$sql = "insert into test (test1) values ('$ciphertext')"; mysql_query($sql);
$sql2 = "select * from test where id = 4"; $result2 = mysql_query($sql2); $row2 = mysql_fetch_array($result2);
echo "<br><br>"; echo $rsa->decrypt(base64_decode($row2{"test1"})); ?>
|