我有这段代码:
$token = $this->hextobin($dataEncrypt);
$key = $this->key_192;
$iv = $this->iv;
$algorithm = 'xxxx';
$mode = 'ecb'; //QUESTION!!!
$td = mcrypt_module_open($algorithm, '', $mode, '') ;
$iv = substr($iv, 0, mcrypt_enc_get_iv_size($td));
$expected_key_size = mcrypt_enc_get_key_size($td);
$key = substr($key, 0, $expected_key_size);
mcrypt_generic_init($td, $key, $iv);
$response = trim(mdecrypt_generic($td, $token), '');
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$response = explode(XXXX,$response);
return $response[0];
但是阅读PHP文档,特别是:http://php.net/manual/en/function.mcrypt-ecb.php说它已经过时,建议使用mcrypt_generic()和mdecrypt_generic()进行替换。 我的问题是如果你以同样的方式问我开放模式如何使用这些功能?
答案 0 :(得分:2)
此处解释了使用public boolean deleteAndSaveAll(ArrayList<MyData> listBean) throws Exception {
boolean transactionCompleted = false;
Session session = HibernateUtils.currentSession();
Transaction tx = session.beginTransaction();
try {
String stringQuery = "DELETE FROM MyData";
Query query = session.createQuery(stringQuery);
query.executeUpdate();
for (MyData MyData : listBean) {
session.save(MyData);
}
tx.commit();
transactionCompleted = true;
} catch (Exception e) {
MyUtils.log("DAO: MyDataDAO error while deleteAndSaveAll : "+e.getMessage());
e.printStackTrace();
if(tx != null){
tx.rollback();
}
throw e;
}finally{
HibernateUtils.closeSession();
}
return transactionCompleted;
}
:
但是,我建议使用更简单的API mcrypt_generic()
:
使用示例:
mcrypt
我注意到mcrypt_encrypt(MCRYPT_3DES, "secret key", "data to encrypt", MCRYPT_MODE_ECB);
上有问号。这是这里解释的加密的“模式”:
http://php.net/manual/en/mcrypt.constants.php
根据PHP文档:
<强>更新强>
如果您使用ecb
模式,请务必设置CBC
,如下所示:
iv