首页 > 解决方案 > 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));

有人知道我的问题的解决方案吗?

先感谢您!

标签: phpphp-openssl

解决方案


解决方案:将密码更改为 aes-256-cbc 允许加密仅包含一个字符的字符串。


推荐阅读