PHP | openssl_get_cipher_methods() Function
Last Updated :
13 Mar, 2020
The openssl_get_cipher_methods() function is an inbuilt function in PHP which is used to get all available cipher methods.
Syntax:
array openssl_get_cipher_methods( bool $aliases = FALSE )
Parameters: This function accepts a single parameter $aliases which decides whether cipher aliases should be there ot not.
Return Value: This function returns an array of available cipher methods.
Below given programs illustrate the openssl_get_cipher_methods() function in PHP:
Program 1: In this program we will list all the available ciphers.
<?php
$ciphers = openssl_get_cipher_methods();
print ( "<pre>" .print_r( $ciphers , true). "</pre>" );
?>
|
Output:
Array
(
[0] => aes-128-cbc
[1] => aes-128-cbc-hmac-sha1
[2] => aes-128-cbc-hmac-sha256
[3] => aes-128-ccm
[4] => aes-128-cfb
[5] => aes-128-cfb1
[6] => aes-128-cfb8
[7] => aes-128-ctr
. . . It will be a long list of all the ciphers.
Program 2: In this program we will check if a cipher is supported or not.
<?php
$ciphers = openssl_get_cipher_methods();
$isSupported1 = in_array( 'aes-128-cfb' , $ciphers );
if ( $isSupported1 ) {
echo 'aes-128-cfb is supported.<br>' ;
}
$isSupported2 = in_array( 'unknown-cipher' , $ciphers );
if (! $isSupported2 ) {
echo 'unknown-cipher is not supported.' ;
}
?>
|
Output:
aes-128-cfb is supported.
unknown-cipher is not supported.
Reference: https://www.php.net/manual/en/function.openssl-get-cipher-methods.php
Share your thoughts in the comments
Please Login to comment...