Search code examples
phpphp-openssl

open-ssl only encrypts strings that have more than 15 characters


im using open-ssl in a project and want to encrypt firstname and surname of users. I discovered a strange behavior from open-ssl: only strings that have more than 15 characters are encrypted. Is it my fault or something not documented?

<?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));

Does anybody know a solution for my problem?

Thank you in advance!


Solution

  • Solution: Changing the cipher to aes-256-cbc allows to encrypt strings with only one character.