我的网站是在 Wordpress 中构建的,我们正在收集需要放入数据库中的个人信息。到目前为止,这是我的 php 插入:
//defined in wp-config.php
$key = KEY_ENCRYPT;
function encrypt($text)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
if($_POST){
//POST object placed in variables
$user_domain = $_POST['domain'];
$s_user = $_POST['s-username'];
$s_pass = $_POST['s-password'];
$w_user = $_POST['w-username'];
$w_pass = $_POST['w-password'];
//encrypting data
$encrypted_server_username = encrypt($s_user);
$encrypted_server_password = encrypt($s_pass);
$encrypted_wordpress_username = encrypt($w_user);
$encrypted_wordpress_password = encrypt($w_pass);
//set up array for options table
$user_website_data = array(
'domain'=>$user_domain,
'server_username'=>$encrypted_server_username,
'server_password'=>$encrypted_server_password,
'wordpress_username'=>$encrypted_wordpress_username,
'wordpress_password'=>$encrypted_wordpress_password
);
update_option($user_domain . '_website_data', $user_website_data);
此代码成功地将信息存储在一个数组中。您甚至可以在http://thewpvalet.staging.wpengine.com/sign-up/?plan=basic上查看此代码的工作和流程。请使用 4242424242424242 作为 CC 号进行测试。
现在我正在尝试在后端管理区域实现解码,以便我可以按域搜索并提取凭据。这是我的代码:
if(isset($_POST['domain'])){
function decrypt($text)
{
$key = KEY_ENCRYPT;
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
$search_domain = $_POST['domain'];
$url_removal = array("http://","www.");
$clean_search_domain = str_replace($url_removal, '', $search_domain);
$user_options = get_option($search_domain.'_website_data');
echo '<strong>Login Information:</strong></br>' .
'Domain:' . $user_options['domain'] . '</br>' .
'Server Username:' . decrypt($user_options['server_username']) . '</br>';
}
这将返回 mcrypt_decrypt() [function.mcrypt-decrypt]: Size of key is too large for this algorithm in /nas/wp/www/staging/thewpvalet/wp-content/plugins/user-info/index.php 第 43 行
知道我在这里做错了什么吗?