SubjectAltName aus CSR in PHP anzeigen
P粉115840076
P粉115840076 2023-09-05 14:30:34
0
1
317
<p>Ich habe Probleme beim Anzeigen des alternativen CSR-Betreffnamens mit PHP. Ich habe etwas recherchiert und einige interessante Dinge gefunden, aber das Problem ist, dass das vor 10 Jahren war und es keinen Code gab, auf den ich verweisen konnte. Der Link lautet wie folgt: Wie erhält man den subjectAltName aus einem CSR in PHP?</p> <p>Die Bibliothek ist phpseclib. Es verfügt über Dokumentation zu CSR, weiß aber nicht, wie man eine solche Bibliothek verwendet. Wissen Sie, wie Sie diese Bibliothek verwenden und alternative Namen für Themen anzeigen? Ich bin nicht gut im Codieren mit Bibliotheken. Jede Hilfe wird sehr geschätzt. Ich habe zwei Tage lang danach gesucht. </p>
P粉115840076
P粉115840076

Antworte allen(1)
P粉351138462

感谢 @neubert 提供我需要的答案,我也想将此分享给任何与我有相同问题的人。

<?php
require __DIR__ . '/vendor/autoload.php';

use phpseclib3\File\X509;
?>

<!DOCTYPE html>
<html>
<head>
    <title>CSR Decode</title>
    <style type="text/css">
        body{
            background-color: #f1f1f1;
            font-family: Arial, sans-serif;
            color: #333333;
        }
        table.section{width:100%;}
        table.ftable td{padding:0px;text-align:center;font-size:13px;}
        h3{
            color: #2e6da4;
            padding: 10px;
            font-size: 20px;
            text-align: center;
            margin-top: 0px;
            margin-bottom: 15px;
            border-radius: 10px;
        }
        table{
            width: 50%;
            margin: auto;
            border-collapse: collapse;
            border: 1px solid #d4d4d4;
            text-align: left;
        }
        th, td{
            padding: 8px;
            border: 1px solid #d4d4d4;
            font-size:15px;
        }
        tr:nth-child(even){
            background-color: #f2f2f2;
        }
        img{
             width: 50%;
            margin: auto;
            margin-bottom: 10px;
        }

        table.table td{border:none;}
                table.table{border:none;}
    input[type="text"] {width: 30%;padding: 5px 20px;border:1px solid white;}
        input[type="submit"]{
            width: 16%;
            padding: 5px 20px;
            background-color:#67BC5A;
            color:white;
            font-weight:bold;
            border:1px solid #67BC5A;
            border-radius:5px;}
    form.form {padding-bottom: 20px;}


    p {
        display: flex;
    justify-content: center;
        font-weight: bold;
        font-size: 24px;
    }

    .csr_info {
        display: flex;
    justify-content: center;
    }

    .csr_info > ul{
        list-style: none;
    }

    .csr_info > ul > li{
        background: url(./img/check.png) no-repeat left;
        font-size: 14px;
    height: 24px;
    padding: 20px 0 0px 58px;
    margin: auto;
    font-weight: normal;
    line-height: 4px;
    }

    </style>
</head>
<body>

<table class="ftable" style="border:none;">
    <tr>
    <td  style="border:none;">
    <h3>Decode CSR</h3>
    <form class="form"action="" method="POST">
        <div>
            <textarea name="csr" rows="22" cols="99"></textarea>
        </div>
        <div>
            <input type="submit" name="submit"  value="Decode CSR">
        </div>
    </form>
    </tr>
    </td>
    </table>
<?php

if(isset($_POST['submit'])){

  $csr = $_POST['csr'];
  $x509 = new X509();
  $csr2 = $x509->loadCSR($csr);
?>
<p>CSR Information</p>
<div class="csr_info">
    <ul>
        <li>
            <strong>Common Name</strong>:
      <?php
        $result = array_values($x509->getDNProp('CN'));
        echo $result[0];
      ?>
        </li>
    <li>
            <strong>Subject Alternative Name:</strong>:
      <?php
        $ext = array_values($x509->getExtension('id-ce-subjectAltName'));
        foreach ($ext as $value) {
          $san = array_values($value);
          echo " , " .$san[0];
        }
      ?>
        </li>
    <li>
            <strong>Organization</strong>:
      <?php
        $result = array_values($x509->getDNProp('O'));
        echo $result[0];
      ?>
        </li>
        <li>
            <strong>Organization Unit</strong>:
      <?php
        $result = array_values($x509->getDNProp('OU'));
        echo $result[0];
      ?>
        </li>
        <li>
            <strong>Locality</strong>:
      <?php
        $result = array_values($x509->getDNProp('L'));
        echo $result[0];
      ?>
        </li>
        <li>
            <strong>State</strong>:
      <?php
        $result = array_values($x509->getDNProp('ST'));
        echo $result[0];
      ?>
        </li>
        <li>
            <strong>Country</strong>:
      <?php
        $result = array_values($x509->getDNProp('C'));
        echo $result[0];
      ?>
        </li>

    </ul>
    <?php
    }

    ?>
</div>

</body>
</html>
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!