小编Asi*_*ony的帖子

由于 Laravel 中的外键约束报告错误

从表中删除一些行时,我在检查中收到以下错误

消息:SQLSTATE[23000]:违反完整性约束:1451 无法删除或更新父行:外键约束失败

我知道错误是由于外键失败引起的。我想显示一条错误消息,指出删除项已被使用。

我正在使用 Laravel 5.8、PHP 7.3、Mysql

有人对此有任何想法吗?

php mysql error-handling foreign-keys laravel

3
推荐指数
1
解决办法
648
查看次数

PHP 中的 AES 加密和 Javascript 中的解密

我有一个应用程序,其中使用 AES CBC 128 算法加密 json 编码数组,然后在 javascript(React/Next Js 项目)中对其进行解密。我在php中的加密如下面的代码所示

加密 PHP


$plaintext = "message to be encrypted";
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($plaintext, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary=true);
$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw );
Run Code Online (Sandbox Code Playgroud)

我在用 Javascript 解密时遇到问题

到目前为止我的代码如下所示

 const baseenc = CryptoJS.enc.Base64.parse(cipher).toString();
  var encrypted = CryptoJS.AES.decrypt(cipher, key, { iv: iv }).toString();
  var plaintext = CryptoJS.enc.Latin1.stringify(encrypted);
Run Code Online (Sandbox Code Playgroud)

任何人都可以显示错误是什么或帮助我获得正确的输出

javascript php encryption aes

0
推荐指数
1
解决办法
510
查看次数