protected function validateKeyLength($key, $module)
    {
        $keySize = strlen($key);
        $keySizeMin = 1;
        $keySizeMax = mcrypt_enc_get_key_size($module);
        $validKeySizes = mcrypt_enc_get_supported_key_sizes($module);
        if ($validKeySizes) {
            if (!in_array($keySize, $validKeySizes)) {
                throw new \InvalidArgumentException('Encryption key length must be one of: ' . implode(', ', $validKeySizes));
            }
        } else {
            if ($keySize < $keySizeMin || $keySize > $keySizeMax) {
                throw new \InvalidArgumentException(sprintf(
                    'Encryption key length must be between %s and %s, inclusive',
                    $keySizeMin,
                    $keySizeMax
                ));
            }
        }
    }
protected function validateKeyLength($key, $module)
    {
        $keySize = strlen($key);
        $keySizeMin = 1;
        $keySizeMax = mcrypt_enc_get_key_size($module);
        $validKeySizes = mcrypt_enc_get_supported_key_sizes($module);
        if ($validKeySizes) {
            if (!in_array($keySize, $validKeySizes)) {
                throw new \InvalidArgumentException('Encryption key length must be one of: ' . implode(', ', $validKeySizes));
            }
        } else {
            if ($keySize < $keySizeMin || $keySize > $keySizeMax) {
                throw new \InvalidArgumentException(sprintf(
                    'Encryption key length must be between %s and %s, inclusive',
                    $keySizeMin,
                    $keySizeMax
                ));
            }
        }
    }
protected function validateKeyLength ( $ key , $ module ) { $ keySize = strlen ( $ key ) ; $ keySizeMin = 1 ; $ keySizeMax = mcrypt_enc_get_key_size ( $ module ) ; $ validKeySizes = mcrypt_enc_get_supported_key_sizes ( $ module ) ; if ( $ validKeySizes ) { if ( ! in_array ( $ keySize , $ validKeySizes ) ) { throw new \ InvalidArgumentException ( 'Encryption key length must be one of: ' . implode ( ', ' , $ validKeySizes ) ) ; } } else { if ( $ keySize < $ keySizeMin || $ keySize > $ keySizeMax ) { throw new \ InvalidArgumentException ( sprintf ( 'Encryption key length must be between %s and %s, inclusive' , $ keySizeMin , $ keySizeMax ) ) ; } } }
Validate encryption key based on valid key sizes for selected cipher and cipher mode
@param  string                    $key    Encryption key
@param  resource                  $module Encryption module
@return void
@throws \InvalidArgumentException         If key size is invalid for selected cipher
Validate encryption key based on valid key sizes for selected cipher and cipher mode