php - open-ssl 只加密超过 15 个字符的字符串
问题描述
我在项目中使用 open-ssl 并希望加密用户的名字和姓氏。我从 open-ssl 发现了一个奇怪的行为:只有超过 15 个字符的字符串才会被加密。是我的错还是没有记录的东西?
<?php
$cipher = 'aes-256-xts';
$privateKey = 'LOOK';
$stringToEncrypt = "Luisa 111 111 11";
$ivLength = openssl_cipher_iv_length($cipher);
$iv = openssl_random_pseudo_bytes($ivLength);
$encryptedData = openssl_encrypt($stringToEncrypt, $cipher, $privateKey, 0, $iv) . ":" . base64_encode($iv);
list($encryptedString, $iv) = explode(':', $encryptedData, 2);
$decryptedData = openssl_decrypt($encryptedString, $cipher, $privateKey, 0, base64_decode($iv));
有人知道我的问题的解决方案吗?
先感谢您!
解决方案
解决方案:将密码更改为 aes-256-cbc 允许加密仅包含一个字符的字符串。
推荐阅读
- django - 未找到带有参数 '('',)' 的 'like_majstor' 的反向操作。尝试了 1 种模式:['likeProfile/(?P
[0-9]+)$'] 问题 - graphics - 将 Layered.jl 画布显示为新窗口
- apache-spark - 火花镶木地板分区,删除分区列
- javascript - 动态添加脚本标签并执行 $(document).ready,无需使用 iframe 或 document.write
- numpy - 偏移旋转矩阵
- react-native - 开玩笑的配置在更新到 26.x 后抛出“type ErrorHandler = (error: mixed, isFatal: boolean) => void”
- python - 如何使用 python 库 mega.py 1.0.8 将文件上传到大型存储平台中的子文件夹?
- excel - 文本文件上的 Excel Office 365 连接字符串
- drupal - 在 Drupal 7 的弹出窗口中禁用登录
- c# - 对象类型“SocketModelLib.Pri_User”没有程序集 ID