openssl_cipher_iv_length

(PHP 5 >= 5.3.3, PHP 7, PHP 8)

openssl_cipher_iv_lengthObtém o comprimento do vetor de inicialização da cifra

Descrição

openssl_cipher_iv_length(string $cipher_algo): int|false

Obtém o comprimento do vetor de inicialização (iv) da cifra

Parâmetros

cipher_algo

O método de criptografia, consulte openssl_get_cipher_methods() para uma lista de valores possíveis.

Valor Retornado

Retorna o comprimento da cifra em caso de sucesso, ou false em caso de falha.

Erros/Exceções

Emite um erro de nível E_WARNING quando o algoritmo de criptografia é desconhecido.

Exemplos

Exemplo #1 Exemplo de openssl_cipher_iv_length()

<?php
$method
= 'AES-128-CBC';
$ivlen = openssl_cipher_iv_length($method);

echo
$ivlen;
?>

O exemplo acima produzirá algo semelhante a:

16
adicione uma nota

Notas Enviadas por Usuários (em inglês) 2 notes

up
10
Tim Hunt
10 years ago
The return value is a length in bytes. (Not bits, or anything else.)
up
-3
Vee W.
7 years ago
<?php$ciphers = openssl_get_cipher_methods();//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;});if (is_array($ciphers)) {    foreach ($ciphers as $cipher) {        echo $cipher.': ';        echo openssl_cipher_iv_length($cipher);        echo "<br>\n";    }}?>Will be...AES-xxx-xxx is 16BF-xxx is 8CAMELLIA-xxx is 16CAST5-xxx is 8IDEA-xxx is 8SEED-xxx is 16lower case:aes-xxx-xxx are mixed between 16 and 12.id-aes-xxx are mixed between 12 and 8.The values above are tested with PHP 5.5 - 5.6 on Windows. In PHP 7.x is different than this.
To Top