{
  "id": "php/openssl-iv-length-mismatch",
  "signature": "Warning: openssl_encrypt(): IV passed is 16 bytes long which is longer than the 8 bytes expected by selected cipher, truncating in /var/www/app/src/Crypto/Encryptor.php on line 23",
  "signature_zh": "警告：openssl_encrypt()：传入的 IV 长度为 16 字节，超过了所选密码期望的 8 字节，将被截断，位于 /var/www/app/src/Crypto/Encryptor.php 第 23 行",
  "regex": "Warning: openssl_encrypt\\(\\): IV passed is \\d+ bytes long which is longer than the \\d+ bytes expected by selected cipher, truncating",
  "domain": "php",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The initialization vector (IV) length provided to `openssl_encrypt` or `openssl_decrypt` does not match the block size required by the selected cipher method (e.g., AES-128-CBC expects 16 bytes, but DES expects 8 bytes).",
  "root_cause_type": "generic",
  "root_cause_zh": "提供给 `openssl_encrypt` 或 `openssl_decrypt` 的初始化向量（IV）长度与所选密码方法所需的块大小不匹配（例如，AES-128-CBC 需要 16 字节，而 DES 需要 8 字节）。",
  "versions": [
    {
      "version": "php 8.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "php 8.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "php 8.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "OpenSSL 3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring the warning and continuing execution",
      "why_fails": "Truncation of the IV can cause decryption failures or security vulnerabilities; the data may not be recoverable or may be improperly encrypted.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using `openssl_random_pseudo_bytes` without specifying the correct length",
      "why_fails": "The function defaults to 16 bytes, which may be incorrect for ciphers like DES (8 bytes) or RC4 (no IV); the length must match the cipher's block size.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use `openssl_cipher_iv_length($cipher)` to determine the correct IV length, then generate the IV accordingly: `$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));`",
      "success_rate": 0.95,
      "how": "Use `openssl_cipher_iv_length($cipher)` to determine the correct IV length, then generate the IV accordingly: `$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Explicitly set the cipher method to match the IV length, e.g., change from `'des'` to `'aes-128-cbc'` if the IV is 16 bytes.",
      "success_rate": 0.9,
      "how": "Explicitly set the cipher method to match the IV length, e.g., change from `'des'` to `'aes-128-cbc'` if the IV is 16 bytes.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use `openssl_cipher_iv_length($cipher)` to determine the correct IV length, then generate the IV accordingly: `$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));`",
    "Explicitly set the cipher method to match the IV length, e.g., change from `'des'` to `'aes-128-cbc'` if the IV is 16 bytes."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.php.net/manual/en/function.openssl-encrypt.php",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}