PHP | openssl_get_cipher_methods() Function
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 // Get all the ciphers $ciphers = openssl_get_cipher_methods(); // Output the cipher to screen 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 // Get all the ciphers $ciphers = openssl_get_cipher_methods(); // Check if aes-128-cfb is supported $isSupported1 = in_array( 'aes-128-cfb' , $ciphers ); if ( $isSupported1 ) { echo 'aes-128-cfb is supported.<br>' ; } // Check if unknown-cipher is supported $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
Contact Us