{
  "id": "php/openssl-invalid-key-format",
  "signature": "Warning: openssl_private_decrypt(): key parameter is not a valid private key in /var/www/app/src/Crypto/Decryptor.php on line 34",
  "signature_zh": "警告：openssl_private_decrypt()：密钥参数不是有效的私钥，位于 /var/www/app/src/Crypto/Decryptor.php 第 34 行",
  "regex": "Warning: openssl_private_decrypt\\(\\): key parameter is not a valid private key in .* on line \\d+",
  "domain": "php",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The private key provided to openssl_private_decrypt() is malformed, missing header/footer, or in an unsupported format (e.g., PKCS#1 instead of PKCS#8).",
  "root_cause_type": "generic",
  "root_cause_zh": "提供给 openssl_private_decrypt() 的私钥格式错误，缺少头部/尾部标记，或使用了不支持的格式（如 PKCS#1 而非 PKCS#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 1.1.1",
      "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": "",
      "why_fails": "The extension is already installed and functional; the error is about key content, not extension availability.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Memory and time settings do not affect key parsing logic.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error occurs after the key is loaded; permissions affect file reading, not key validation.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Convert the private key from PKCS#1 to PKCS#8 format using OpenSSL command: `openssl pkcs8 -topk8 -inform PEM -outform PEM -in private.pem -out private_pkcs8.pem -nocrypt`",
      "success_rate": 0.85,
      "how": "Convert the private key from PKCS#1 to PKCS#8 format using OpenSSL command: `openssl pkcs8 -topk8 -inform PEM -outform PEM -in private.pem -out private_pkcs8.pem -nocrypt`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure the key string includes the correct header and footer (e.g., '-----BEGIN PRIVATE KEY-----' and '-----END PRIVATE KEY-----') and no extra whitespace or line breaks.",
      "success_rate": 0.75,
      "how": "Ensure the key string includes the correct header and footer (e.g., '-----BEGIN PRIVATE KEY-----' and '-----END PRIVATE KEY-----') and no extra whitespace or line breaks.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `openssl_pkey_get_private()` to validate the key before passing it to decryption functions; if it returns false, log the OpenSSL error with `openssl_error_string()`.",
      "success_rate": 0.9,
      "how": "Use `openssl_pkey_get_private()` to validate the key before passing it to decryption functions; if it returns false, log the OpenSSL error with `openssl_error_string()`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 OpenSSL 命令将私钥从 PKCS#1 转换为 PKCS#8 格式：`openssl pkcs8 -topk8 -inform PEM -outform PEM -in private.pem -out private_pkcs8.pem -nocrypt`",
    "确保密钥字符串包含正确的头部和尾部（如 '-----BEGIN PRIVATE KEY-----' 和 '-----END PRIVATE KEY-----'），且没有多余的空格或换行。",
    "在传递给解密函数之前，使用 `openssl_pkey_get_private()` 验证密钥；如果返回 false，使用 `openssl_error_string()` 记录 OpenSSL 错误。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.php.net/manual/en/function.openssl-private-decrypt.php",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2024-03-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}