PHP openssl_get_cipher_methods OpenSSL 函数

  • 定义和用法

    openssl_get_cipher_methods - 获取可用的加密算法
  • 版本支持

    PHP4 PHP5 PHP7
    不支持 v5.3.0+支持 支持
  • 语法

    openssl_get_cipher_methods( [ bool $aliases = false ] )
    openssl_get_cipher_methods() 获取可用的加密算法的列表。
  • 参数

    参数 必需的 描述
    aliases 如果密码别名应该包含在返回的数组中,则设置为 TRUE.
  • 返回值

    一个包含可用加密算法的数组。
  • 示例

    $ciphers             = openssl_get_cipher_methods();
    $ciphers_and_aliases = openssl_get_cipher_methods(true);
    $cipher_aliases      = array_diff($ciphers_and_aliases, $ciphers);
    
    //ECB mode should be avoided
    $ciphers = array_filter( $ciphers, function($n) { return stripos($n,"ecb")===FALSE; } );
    
    //At least as early as Aug 2016, Openssl declared the following weak: RC2, RC4, DES, 3DES, MD5 based
    $ciphers = array_filter( $ciphers, function($c) { return stripos($c,"des")===FALSE; } );
    $ciphers = array_filter( $ciphers, function($c) { return stripos($c,"rc2")===FALSE; } );
    $ciphers = array_filter( $ciphers, function($c) { return stripos($c,"rc4")===FALSE; } );
    $ciphers = array_filter( $ciphers, function($c) { return stripos($c,"md5")===FALSE; } );
    $cipher_aliases = array_filter($cipher_aliases,function($c) { return stripos($c,"des")===FALSE; } );
    $cipher_aliases = array_filter($cipher_aliases,function($c) { return stripos($c,"rc2")===FALSE; } );
    
    print_r($ciphers);
    print_r($cipher_aliases);
    
    尝试一下
  • 相关页面

    openssl_get_md_methods() - 获取可用的摘要算法