Saturday, January 17, 2026
HomeLanguagesPHP | openssl_cipher_iv_length() Function

PHP | openssl_cipher_iv_length() Function

The openssl_cipher_iv_length() function is an inbuilt function in PHP which is used to get the cipher initialization vector (iv) length. An initialization vector (iv) is an arbitrary number that is used along with a secret key for data encryption. Each cipher method has an initialization vector length associated with it.

Syntax:

int openssl_cipher_iv_length( string $method )

Parameters: This function accepts a single parameter $method which holds the cipher method.

Return Value: This function returns cipher length on success or FALSE on failure.

Exceptions: This function throws E_WARNING level error when the cipher algorithm is unknown.

Below examples illustrate the openssl_cipher_iv_length() function in PHP:

Example 1: In this program we will get iv length of aes-128-gcm cipher algorithm




<?php
  
// The cipher method to get iv length of
$method = 'aes-128-gcm';
  
// Get the iv length
$ivl = openssl_cipher_iv_length($method);
  
// Output the ivl to
echo $ivl;
?>


Output:

12

Example 2: In this program, we will get iv length of camellia-192-cfb8 cipher algorithm




<?php
  
// The cipher method to get iv length of
$method = 'camellia-192-cfb8';
  
// Get the iv length
$ivl = openssl_cipher_iv_length($method);
  
// Output the ivl to
echo $ivl;
?>


Output:

16

Reference: https://www.php.net/manual/en/function.openssl-cipher-iv-length.php

RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS