db 字段没问题。
您可以使用unique encryption key for each user,
这样 db 中的数据将由该密钥加密,该密钥是long unique hash
那么你可以使用 2 个独立的数据库(不是表)
1db for users encryption keys
1db for users data encrypted by keys
然后我与您分享我的encrypt/decrypt library
哪些用途AES
,这是我发现的最好的:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Crypto encrypt/decrypt Class it uses AES by $secret_key
*
* @access public
* @param array/value
* @return array/value
*/
class Crypto(){
function encrypt($data,$secret_key){
$array = array();
if(is_array($data)){
foreach($data as $key=>$value){
$array[$key] = trim(
base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$secret_key, $value,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND)
)
)
);
}
return $array;
}else{
return trim(
base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$secret_key, $data,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND)
)
)
);
}
}
function decrypt($data,$secret_key)
{
$array = array();
if(is_array($data)){
foreach($data as $key=>$value){
$array[$key] = trim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$secret_key,
base64_decode($value),
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND
)
)
);
}
return $array;
}else{
return trim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$sSecretKey,
base64_decode($sValue),
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND
)
)
);
}
}
}
//end class Crypto
注意: $secret_key
是用户密钥,$data
是您要加密或解密的数据