我有一个代码库,它在数据库中存储了一些敏感数据。在将数据存储到数据库之前,我使用
this Crypto library
(
docs here
为了解密它,我使用下面的
use \Defuse\Crypto\Crypto;
use \Defuse\Crypto\Exception as Ex;
// The following is inside a class, but for clarity I only copy pasted this part
try {
return Crypto::decrypt($aStr, Crypt::$cryptoKey);
} catch (Ex\InvalidCiphertextException $ex) { // VERY IMPORTANT
// Either:
// 1. The ciphertext was modified by the attacker,
// 2. The key is wrong, or
// 3. $ciphertext is not a valid ciphertext or was corrupted.
// Assume the worst.
die('The ciphertext has been tampered with! Message:'.$ex->getMessage());
}
// I've got some more catch blocks here but they're not relevant for this question
这段代码工作得很好,但今天我偶然发现了一个数据库记录,它让整个事情都死在这个数据库上
InvalidCiphertextException
接住。我已经用一些示例代码手动尝试过了,但是我总是得到
.
我假定数据是损坏的,但我不确定是否是这样。
该记录位于一个表的中间,表中有15000条记录,这些记录都很好,代码的这一部分已经很久没有突然变化了。