CakeFest 2024: The Official CakePHP Conference

mcrypt_get_block_size

(PHP 4, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)

mcrypt_get_block_size指定した暗号のブロックサイズを得る

警告

この関数は PHP 7.1.0 で 非推奨となり、PHP 7.2.0 で削除 されました。この関数に頼らないことを強く推奨します。

説明

mcrypt_get_block_size(int $cipher): int|false
mcrypt_get_block_size(string $cipher, string $mode): int|false

最初のプロトタイプは libmcrypt 2.2.x とリンクした場合であり、2 番目 のものは libmcrypt 2.4.x あるいは 2.5.x とリンクした場合です。

mcrypt_get_block_size()は、指定した cipher のブロック長を返します (暗号化モードと組み合わせます)。

mcrypt_enc_get_block_size() 関数のほうがより有用です。というのもこちらの関数は mcrypt_module_open() が返すリソースを使用するからです。

パラメータ

cipher

MCRYPT_暗号名 定数のいずれか、 あるいはアルゴリズム名をあらわす文字列。

mode

定数 MCRYPT_MODE_モード名、あるいは文字列 "ecb", "cbc", "cfb", "ofb", "nofb" ,"stream" のいずれか。

戻り値

アルゴリズムのブロックサイズをバイト数で返します。失敗した場合に false を返します.

例1 mcrypt_get_block_size() の例

この例は、libmcrypt 2.4.x および 2.5.x を対象にリンクした際の使用法を示すものです。

<?php

echo mcrypt_get_block_size('tripledes', 'ecb'); // 8

?>

参考

add a note

User Contributed Notes 1 note

up
-5
mehaase at gmail dot com
9 years ago
You should explain that the block size is return in BYTES, not the more commonly used unit, bits. Many readers are not going to know the DES block size and figure this out on their own.
To Top