PHP has OpenSSL extension that provides various functions related with cryptography, such as symmetric and asymmetric encryption and decryption, private and public key pair generation, etc.
Since PHP 8.2, we can use the openssl_cipher_key_length function to get the cipher key length. This function returns key length in bytes for any supported OpenSSL cipher. If cipher is unknown, the function returns false and emits a warning.
<?php
echo openssl_cipher_key_length('aes-256-cbc'); // 32
Note: PHP has similar openssl_cipher_iv_length function. It allows getting the cipher initialization vector (IV) length.
Leave a Comment
Cancel reply