<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          HalitePHP項(xiàng)目中l(wèi)ibsodium封裝

          聯(lián)合創(chuàng)作 · 2023-09-30 07:58

          Halite 是PHP項(xiàng)目中一個(gè)簡單的libsodium封裝包。Halite提供高級的加密接口,依靠其所有潛在的密碼操作libsodium。

          Halite 基本 API:

          示例1:加密解密消息

          首先,生成一個(gè)key

          <?php
          use ParagonIE\Halite\KeyFactory;
          
          $encKey = KeyFactory::generateEncryptionKey();
          KeyFactory::save($encKey, '/path/outside/webroot/encryption.key');

          然后,加密解密消息

          <?php
          use ParagonIE\Halite\HiddenString;
          use ParagonIE\Halite\KeyFactory;
          use ParagonIE\Halite\Symmetric\Crypto as Symmetric;
          
          $encryptionKey = KeyFactory::loadEncryptionKey('/path/outside/webroot/encryption.key');
          
          $message = new HiddenString('This is a confidential message for your eyes only.');
          $ciphertext = Symmetric::encrypt($message, $encryptionKey);
          
          $decrypted = Symmetric::decrypt($ciphertext, $encryptionKey);
          
          var_dump($decrypted === $message); // bool(true)

          示例2:用password-derived key 加密消息

          <?php
          use ParagonIE\Halite\HiddenString;
          use ParagonIE\Halite\KeyFactory;
          use ParagonIE\Halite\Symmetric\Crypto as Symmetric;
          
          $passwd = new HiddenString('correct horse battery staple');
          // Use random_bytes(16); to generate the salt:
          $salt = "\xdd\x7b\x1e\x38\x75\x9f\x72\x86\x0a\xe9\xc8\x58\xf6\x16\x0d\x3b";
          
          $encryptionKey = KeyFactory::deriveEncryptionKey($passwd, $salt);
          
          $message = new HiddenString('This is a confidential message for your eyes only.');
          $ciphertext = Symmetric::encrypt($message, $encryptionKey);
          echo $ciphertext, "\n";
          瀏覽 21
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  中文字幕av网 | 国产 —一级a毛一级a看免费 | 男人的天堂伊人 | 久久嫩穴| 俺也去av |