import{_ as p,o as l,c as o,k as s,a as n,X as a}from"./chunks/framework.6e839c56.js";const C=JSON.parse('{"title":"Cryptor","description":"","frontmatter":{},"headers":[],"relativePath":"api/packages/cryptor.md","filePath":"api/packages/cryptor.md"}'),e={name:"api/packages/cryptor.md"},t=s("h1",{id:"Cryptor",tabindex:"-1"},[n("Cryptor "),s("a",{class:"header-anchor",href:"#Cryptor","aria-label":'Permalink to "Cryptor"'},"​")],-1),c=s("p",null,"cryptor包包含数据加密和解密功能。支持 base64, md5, hmac, hash, aes, des, rsa。",-1),r=s("div",{STYLE:"page-break-after: always;"},null,-1),y=s("h2",{id:"源码-",tabindex:"-1"},[n("源码: "),s("a",{class:"header-anchor",href:"#源码-","aria-label":'Permalink to "源码:"'},"​")],-1),F=s("ul",null,[s("li",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/cryptor/basic.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/cryptor/basic.go")]),s("li",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/cryptor/crypto.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/cryptor/crypto.go")])],-1),i=s("div",{STYLE:"page-break-after: always;"},null,-1),d=a(`<h2 id="用法-" tabindex="-1">用法: <a class="header-anchor" href="#用法-" aria-label="Permalink to &quot;用法:&quot;">​</a></h2><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,2),E=s("div",{STYLE:"page-break-after: always;"},null,-1),A=a('<h2 id="目录" tabindex="-1">目录 <a class="header-anchor" href="#目录" aria-label="Permalink to &quot;目录&quot;">​</a></h2><ul><li><a href="#AesEcbEncrypt">AesEcbEncrypt</a></li><li><a href="#AesEcbDecrypt">AesEcbDecrypt</a></li><li><a href="#AesCbcEncrypt">AesCbcEncrypt</a></li><li><a href="#AesCbcDecrypt">AesCbcDecrypt</a></li><li><a href="#AesCtrCrypt">AesCtrCrypt</a></li><li><a href="#AesCfbEncrypt">AesCfbEncrypt</a></li><li><a href="#AesCfbDecrypt">AesCfbDecrypt</a></li><li><a href="#AesOfbEncrypt">AesOfbEncrypt</a></li><li><a href="#AesOfbDecrypt">AesOfbDecrypt</a></li><li><a href="#Base64StdEncode">Base64StdEncode</a></li><li><a href="#Base64StdDecode">Base64StdDecode</a></li><li><a href="#DesEcbEncrypt">DesEcbEncrypt</a></li><li><a href="#DesEcbDecrypt">DesEcbDecrypt</a></li><li><a href="#DesCbcEncrypt">DesCbcEncrypt</a></li><li><a href="#DesCbcDecrypt">DesCbcDecrypt</a></li><li><a href="#DesCtrCrypt">DesCtrCrypt</a></li><li><a href="#DesCfbEncrypt">DesCfbEncrypt</a></li><li><a href="#DesCfbDecrypt">DesCfbDecrypt</a></li><li><a href="#DesOfbEncrypt">DesOfbEncrypt</a></li><li><a href="#DesOfbDecrypt">DesOfbDecrypt</a></li><li><a href="#HmacMd5">HmacMd5</a></li><li><a href="#HmacMd5WithBase64">HmacMd5WithBase64</a></li><li><a href="#HmacSha1">HmacSha1</a></li><li><a href="#HmacSha1WithBase64">HmacSha1WithBase64</a></li><li><a href="#HmacSha256">HmacSha256</a></li><li><a href="#HmacSha256WithBase64">HmacSha256WithBase64</a></li><li><a href="#HmacSha512">HmacSha512</a></li><li><a href="#HmacSha512WithBase64">HmacSha512WithBase64</a></li><li><a href="#Md5String">Md5String</a></li><li><a href="#Md5StringWithBase64">Md5StringWithBase64</a></li><li><a href="#Md5Byte">Md5Byte</a></li><li><a href="#Md5ByteWithBase64">Md5ByteWithBase64</a></li><li><a href="#Md5File">Md5File</a></li><li><a href="#Sha1">Sha1</a></li><li><a href="#Sha1WithBase64">Sha1WithBase64</a></li><li><a href="#Sha256">Sha256</a></li><li><a href="#Sha256WithBase64">Sha256WithBase64</a></li><li><a href="#Sha512">Sha512</a></li><li><a href="#Sha512WithBase64">Sha512WithBase64</a></li><li><a href="#GenerateRsaKey">GenerateRsaKey</a></li><li><a href="#RsaEncrypt">RsaEncrypt</a></li><li><a href="#RsaDecrypt">RsaDecrypt</a></li></ul>',2),u=s("div",{STYLE:"page-break-after: always;"},null,-1),h=a(`<link rel="stylesheet" type="text/css" href="/styles/api_doc.css"><h2 id="文档" tabindex="-1">文档 <a class="header-anchor" href="#文档" aria-label="Permalink to &quot;文档&quot;">​</a></h2><h3 id="AesEcbEncrypt" tabindex="-1"><span id="AesEcbEncrypt">AesEcbEncrypt</span> <a class="header-anchor" href="#AesEcbEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesEcbEncrypt&quot;&gt;AesEcbEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES ECB算法模式加密数据. 参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesEcbEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesEcbEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/zI6xsmuQRbn" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesEcbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesEcbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesEcbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesEcbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesEcbDecrypt" tabindex="-1"><span id="AesEcbDecrypt">AesEcbDecrypt</span> <a class="header-anchor" href="#AesEcbDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesEcbDecrypt&quot;&gt;AesEcbDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES ECB算法模式解密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesEcbDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesEcbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/zI6xsmuQRbn" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesEcbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesEcbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesEcbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesEcbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesCbcEncrypt" tabindex="-1"><span id="AesCbcEncrypt">AesCbcEncrypt</span> <a class="header-anchor" href="#AesCbcEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesCbcEncrypt&quot;&gt;AesCbcEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES CBC算法模式加密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesCbcEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesCbcEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/IOq_g8_lKZD" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCbcEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCbcDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCbcEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCbcDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesCbcDecrypt" tabindex="-1"><span id="AesCbcDecrypt">AesCbcDecrypt</span> <a class="header-anchor" href="#AesCbcDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesCbcDecrypt&quot;&gt;AesCbcDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES CBC算法模式解密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesCbcDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesCbcDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/IOq_g8_lKZD" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCbcEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCbcDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCbcEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCbcDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesCtrCrypt" tabindex="-1"><span id="AesCtrCrypt">AesCtrCrypt</span> <a class="header-anchor" href="#AesCtrCrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesCtrCrypt&quot;&gt;AesCtrCrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES CTR算法模式加密/解密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesCtrCrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesCtrCrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/SpaZO0-5Nsp" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCtrCrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCtrCrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCtrCrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCtrCrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesCfbEncrypt" tabindex="-1"><span id="AesCfbEncrypt">AesCfbEncrypt</span> <a class="header-anchor" href="#AesCfbEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesCfbEncrypt&quot;&gt;AesCfbEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES CFB算法模式加密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesCfbEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesCfbEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/tfkF10B13kH" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesCfbDecrypt" tabindex="-1"><span id="AesCfbDecrypt">AesCfbDecrypt</span> <a class="header-anchor" href="#AesCfbDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesCfbDecrypt&quot;&gt;AesCfbDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES CFB算法模式解密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/tfkF10B13kH" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesOfbEncrypt" tabindex="-1"><span id="AesOfbEncrypt">AesOfbEncrypt</span> <a class="header-anchor" href="#AesOfbEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesOfbEncrypt&quot;&gt;AesOfbEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES OFB算法模式加密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesOfbEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesOfbEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/VtHxtkUj-3F" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesOfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesOfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="AesOfbDecrypt" tabindex="-1"><span id="AesCfbDecrypt">AesOfbDecrypt</span> <a class="header-anchor" href="#AesOfbDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;AesCfbDecrypt&quot;&gt;AesOfbDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用AES OFB算法模式解密数据，参数\`key\`的长度是16, 24 or 32。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">AesOfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">AesOfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/VtHxtkUj-3F" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefghijklmnop</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesOfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">AesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefghijklmnop</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesOfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">AesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Base64StdEncode" tabindex="-1"><span id="Base64StdEncode">Base64StdEncode</span> <a class="header-anchor" href="#Base64StdEncode" aria-label="Permalink to &quot;&lt;span id=&quot;Base64StdEncode&quot;&gt;Base64StdEncode&lt;/span&gt;&quot;">​</a></h3><p>将字符串base64编码。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Base64StdEncode</span><span style="color:#F6F6F4;">(s </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Base64StdEncode</span><span style="color:#999999;">(</span><span style="color:#393A34;">s </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/VOaUyQUreoK" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    base64Str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Base64StdEncode</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(base64Str)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// aGVsbG8=</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">base64Str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Base64StdEncode</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">base64Str</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// aGVsbG8=</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Base64StdDecode" tabindex="-1"><span id="Base64StdDecode">Base64StdDecode</span> <a class="header-anchor" href="#Base64StdDecode" aria-label="Permalink to &quot;&lt;span id=&quot;Base64StdDecode&quot;&gt;Base64StdDecode&lt;/span&gt;&quot;">​</a></h3><p>解码base64字符串。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Base64StdDecode</span><span style="color:#F6F6F4;">(s </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Base64StdDecode</span><span style="color:#999999;">(</span><span style="color:#393A34;">s </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/RWQylnJVgIe" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Base64StdDecode</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">aGVsbG8=</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(str)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Base64StdDecode</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">aGVsbG8=</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesEcbEncrypt" tabindex="-1"><span id="DesEcbEncrypt">DesEcbEncrypt</span> <a class="header-anchor" href="#DesEcbEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesEcbEncrypt&quot;&gt;DesEcbEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES ECB算法模式加密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesEcbEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesEcbEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/8qivmPeZy4P" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesEcbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesEcbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesEcbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesEcbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesEcbDecrypt" tabindex="-1"><span id="DesEcbDecrypt">DesEcbDecrypt</span> <a class="header-anchor" href="#DesEcbDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesEcbDecrypt&quot;&gt;DesEcbDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES ECB算法模式解决密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesEcbDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesEcbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/8qivmPeZy4P" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesEcbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesEcbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesEcbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesEcbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesCbcEncrypt" tabindex="-1"><span id="DesCbcEncrypt">DesCbcEncrypt</span> <a class="header-anchor" href="#DesCbcEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesCbcEncrypt&quot;&gt;DesCbcEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES CBC算法模式加密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesCbcEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesCbcEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/4cC4QvWfe3_1" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCbcEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCbcDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCbcEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCbcDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesCbcDecrypt" tabindex="-1"><span id="DesCbcDecrypt">DesCbcDecrypt</span> <a class="header-anchor" href="#DesCbcDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesCbcDecrypt&quot;&gt;DesCbcDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES CBC算法模式解密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesCbcDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesCbcDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/4cC4QvWfe3_1" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCbcEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCbcDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCbcEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCbcDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesCtrCrypt" tabindex="-1"><span id="DesCtrCrypt">DesCtrCrypt</span> <a class="header-anchor" href="#DesCtrCrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesCtrCrypt&quot;&gt;DesCtrCrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES CTR算法模式加密/解密数据，参数\`key\`的长度是8</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesCtrCrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesCtrCrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/9-T6OjKpcdw" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCtrCrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCtrCrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCtrCrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCtrCrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesCfbEncrypt" tabindex="-1"><span id="DesCfbEncrypt">DesCfbEncrypt</span> <a class="header-anchor" href="#DesCfbEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesCfbEncrypt&quot;&gt;DesCfbEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES CFB算法模式加密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesCfbEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesCfbEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/y-eNxcFBlxL" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesCfbDecrypt" tabindex="-1"><span id="DesCfbDecrypt">DesCfbDecrypt</span> <a class="header-anchor" href="#DesCfbDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesCfbDecrypt&quot;&gt;DesCfbDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES CFB算法模式解决密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/y-eNxcFBlxL" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesCfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesCfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesOfbEncrypt" tabindex="-1"><span id="DesOfbEncrypt">DesOfbEncrypt</span> <a class="header-anchor" href="#DesOfbEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesOfbEncrypt&quot;&gt;DesOfbEncrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES OFB算法模式加密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesOfbEncrypt</span><span style="color:#F6F6F4;">(data, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesOfbEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/74KmNadjN1J" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesOfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesOfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesOfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesOfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DesOfbDecrypt" tabindex="-1"><span id="DesOfbDecrypt">DesOfbDecrypt</span> <a class="header-anchor" href="#DesOfbDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;DesOfbDecrypt&quot;&gt;DesOfbDecrypt&lt;/span&gt;&quot;">​</a></h3><p>使用DES OFB算法模式解密数据，参数\`key\`的长度是8。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DesOfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, key []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DesOfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/74KmNadjN1J" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abcdefgh</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesOfbEncrypt</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(data), []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">DesOfbDecrypt</span><span style="color:#F6F6F4;">(encrypted, []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(key))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abcdefgh</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesOfbEncrypt</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">),</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">DesOfbDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">key</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacMd5" tabindex="-1"><span id="HmacMd5">HmacMd5</span> <a class="header-anchor" href="#HmacMd5" aria-label="Permalink to &quot;&lt;span id=&quot;HmacMd5&quot;&gt;HmacMd5&lt;/span&gt;&quot;">​</a></h3><p>获取字符串md5 hmac值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacMd5</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacMd5</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/uef0q1fz53I" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacMd5</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// e834306eab892d872525d4918a7a639a</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacMd5</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// e834306eab892d872525d4918a7a639a</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacMd5WithBase64" tabindex="-1"><span id="HmacMd5WithBase64">HmacMd5WithBase64</span> <a class="header-anchor" href="#HmacMd5WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;HmacMd5WithBase64&quot;&gt;HmacMd5WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串md5 hmac base64字符串值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacMd5WithBase64</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacMd5WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/UY0ng2AefFC" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacMd5WithBase64</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 6DQwbquJLYclJdSRinpjmg==</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacMd5WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 6DQwbquJLYclJdSRinpjmg==</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacSha1" tabindex="-1"><span id="HmacSha1">HmacSha1</span> <a class="header-anchor" href="#HmacSha1" aria-label="Permalink to &quot;&lt;span id=&quot;HmacSha1&quot;&gt;HmacSha1&lt;/span&gt;&quot;">​</a></h3><p>获取字符串的sha1 hmac值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacSha1</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacSha1</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/1UI4oQ4WXKM" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacSha1</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 5c6a9db0cccb92e36ed0323fd09b7f936de9ace0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacSha1</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 5c6a9db0cccb92e36ed0323fd09b7f936de9ace0</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacSha1WithBase64" tabindex="-1"><span id="HmacSha1WithBase64">HmacSha1WithBase64</span> <a class="header-anchor" href="#HmacSha1WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;HmacSha1WithBase64&quot;&gt;HmacSha1WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串的sha1 base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacSha1WithBase64</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacSha1WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/47JmmGrnF7B" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacSha1WithBase64</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// XGqdsMzLkuNu0DI/0Jt/k23prOA=</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacSha1WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// XGqdsMzLkuNu0DI/0Jt/k23prOA=</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacSha256" tabindex="-1"><span id="HmacSha256">HmacSha256</span> <a class="header-anchor" href="#HmacSha256" aria-label="Permalink to &quot;&lt;span id=&quot;HmacSha256&quot;&gt;HmacSha256&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha256 hmac值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacSha256</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacSha256</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/HhpwXxFhhC0" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacSha256</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 315bb93c4e989862ba09cb62e05d73a5f376cb36f0d786edab0c320d059fde75</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacSha256</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 315bb93c4e989862ba09cb62e05d73a5f376cb36f0d786edab0c320d059fde75</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacSha256WithBase64" tabindex="-1"><span id="HmacSha256WithBase64">HmacSha256WithBase64</span> <a class="header-anchor" href="#HmacSha256WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;HmacSha256WithBase64&quot;&gt;HmacSha256WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha256 hmac base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacSha256WithBase64</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacSha256WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/EKbkUvPTLwO" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacSha256WithBase64</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// MVu5PE6YmGK6Ccti4F1zpfN2yzbw14btqwwyDQWf3nU=</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacSha256WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// MVu5PE6YmGK6Ccti4F1zpfN2yzbw14btqwwyDQWf3nU=</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacSha512" tabindex="-1"><span id="HmacSha512">HmacSha512</span> <a class="header-anchor" href="#HmacSha512" aria-label="Permalink to &quot;&lt;span id=&quot;HmacSha512&quot;&gt;HmacSha512&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha512 hmac值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacSha512</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacSha512</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/59Od6m4A0Ud" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacSha512</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// dd8f1290a9dd23d354e2526d9a2e9ce8cffffdd37cb320800d1c6c13d2efc363288376a196c5458daf53f8e1aa6b45a6d856303d5c0a2064bff9785861d48cfc</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacSha512</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// dd8f1290a9dd23d354e2526d9a2e9ce8cffffdd37cb320800d1c6c13d2efc363288376a196c5458daf53f8e1aa6b45a6d856303d5c0a2064bff9785861d48cfc</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HmacSha512WithBase64" tabindex="-1"><span id="HmacSha512WithBase64">HmacSha512WithBase64</span> <a class="header-anchor" href="#HmacSha512WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;HmacSha512WithBase64&quot;&gt;HmacSha512WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha512 hmac base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HmacSha512WithBase64</span><span style="color:#F6F6F4;">(str, key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HmacSha512WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/c6dSe3E2ydU" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">	key </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">12345</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	hms </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">HmacSha512WithBase64</span><span style="color:#F6F6F4;">(str, key)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(hms)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// 3Y8SkKndI9NU4lJtmi6c6M///dN8syCADRxsE9Lvw2Mog3ahlsVFja9T+OGqa0Wm2FYwPVwKIGS/+XhYYdSM/A==</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">key</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">12345</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#B07D48;">hms</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">HmacSha512WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">,</span><span style="color:#393A34;"> key</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">hms</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// 3Y8SkKndI9NU4lJtmi6c6M///dN8syCADRxsE9Lvw2Mog3ahlsVFja9T+OGqa0Wm2FYwPVwKIGS/+XhYYdSM/A==</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Md5String" tabindex="-1"><span id="Md5String">Md5String</span> <a class="header-anchor" href="#Md5String" aria-label="Permalink to &quot;&lt;span id=&quot;Md5String&quot;&gt;Md5String&lt;/span&gt;&quot;">​</a></h3><p>获取字符串md5值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Md5String</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Md5String</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/1bLcVetbTOI" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    md5Str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Md5String</span><span style="color:#F6F6F4;">(str)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(md5Str)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 5d41402abc4b2a76b9719d911017c592</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">md5Str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Md5String</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">md5Str</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 5d41402abc4b2a76b9719d911017c592</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Md5StringWithBase64" tabindex="-1"><span id="Md5StringWithBase64">Md5StringWithBase64</span> <a class="header-anchor" href="#Md5StringWithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;Md5StringWithBase64&quot;&gt;Md5StringWithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串md5 base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Md5StringWithBase64</span><span style="color:#F6F6F4;">(s </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Md5StringWithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">s </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/Tcb-Z7LN2ax" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    md5Str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Md5StringWithBase64</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(md5Str)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// XUFAKrxLKna5cZ2REBfFkg==</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">md5Str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Md5StringWithBase64</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">md5Str</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// XUFAKrxLKna5cZ2REBfFkg==</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Md5Byte" tabindex="-1"><span id="Md5Byte">Md5Byte</span> <a class="header-anchor" href="#Md5Byte" aria-label="Permalink to &quot;&lt;span id=&quot;Md5Byte&quot;&gt;Md5Byte&lt;/span&gt;&quot;">​</a></h3><p>获取byte slice的md5值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Md5Byte</span><span style="color:#F6F6F4;">(data []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Md5Byte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/suraalH8lyC" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    md5Str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Md5Byte</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">{</span><span style="color:#DEE492;">&#39;</span><span style="color:#BF9EEE;">a</span><span style="color:#DEE492;">&#39;</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(md5Str)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// 0cc175b9c0f1b6a831c399e269772661</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">md5Str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Md5Byte</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">{</span><span style="color:#B5695999;">&#39;</span><span style="color:#A65E2B;">a</span><span style="color:#B5695999;">&#39;</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">md5Str</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// 0cc175b9c0f1b6a831c399e269772661</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Md5ByteWithBase64" tabindex="-1"><span id="Md5ByteWithBase64">Md5ByteWithBase64</span> <a class="header-anchor" href="#Md5ByteWithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;Md5ByteWithBase64&quot;&gt;Md5ByteWithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取byte slice的md5 base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Md5ByteWithBase64</span><span style="color:#F6F6F4;">(data []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Md5ByteWithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">data </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/Lx4gH7Vdr5_y" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    md5Str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Md5ByteWithBase64</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(md5Str)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// XUFAKrxLKna5cZ2REBfFkg==</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">md5Str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Md5ByteWithBase64</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">md5Str</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// XUFAKrxLKna5cZ2REBfFkg==</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Md5File" tabindex="-1"><span id="Md5File">Md5File</span> <a class="header-anchor" href="#Md5File" aria-label="Permalink to &quot;&lt;span id=&quot;Md5File&quot;&gt;Md5File&lt;/span&gt;&quot;">​</a></h3><p>获取文件md5值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Md5File</span><span style="color:#F6F6F4;">(filepath </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) (</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Md5File</span><span style="color:#999999;">(</span><span style="color:#393A34;">filepath </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>示例:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    s </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Md5File</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">./main.go</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(s)</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">s</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Md5File</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">./main.go</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span><span style="color:#393A34;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">s</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Sha1" tabindex="-1"><span id="Sha1">Sha1</span> <a class="header-anchor" href="#Sha1" aria-label="Permalink to &quot;&lt;span id=&quot;Sha1&quot;&gt;Sha1&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha1值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Sha1</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Sha1</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/_m_uoD1deMT" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Sha1</span><span style="color:#F6F6F4;">(str)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Sha1</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Sha1WithBase64" tabindex="-1"><span id="Sha1WithBase64">Sha1WithBase64</span> <a class="header-anchor" href="#Sha1WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;Sha1WithBase64&quot;&gt;Sha1WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha1 base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Sha1WithBase64</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Sha1WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/fSyx-Gl2l2-" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Sha1WithBase64</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// qvTGHdzF6KLavt4PO0gs2a6pQ00=</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Sha1WithBase64</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// qvTGHdzF6KLavt4PO0gs2a6pQ00=</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Sha256" tabindex="-1"><span id="Sha256">Sha256</span> <a class="header-anchor" href="#Sha256" aria-label="Permalink to &quot;&lt;span id=&quot;Sha256&quot;&gt;Sha256&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha256值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Sha256</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Sha256</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/tU9tfBMIAr1" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Sha256</span><span style="color:#F6F6F4;">(str)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Sha256</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Sha256WithBase64" tabindex="-1"><span id="Sha256WithBase64">Sha256WithBase64</span> <a class="header-anchor" href="#Sha256WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;Sha256WithBase64&quot;&gt;Sha256WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha256 base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Sha256WithBase64</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Sha256WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/85IXJHIal1k" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Sha256WithBase64</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Sha256WithBase64</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Sha512" tabindex="-1"><span id="Sha512">Sha512</span> <a class="header-anchor" href="#Sha512" aria-label="Permalink to &quot;&lt;span id=&quot;Sha512&quot;&gt;Sha512&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha512值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Sha512</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Sha512</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/3WsvLYZxsHa" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    str </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Sha512</span><span style="color:#F6F6F4;">(str)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">str</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Sha512</span><span style="color:#999999;">(</span><span style="color:#393A34;">str</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Sha512WithBase64" tabindex="-1"><span id="Sha512WithBase64">Sha512WithBase64</span> <a class="header-anchor" href="#Sha512WithBase64" aria-label="Permalink to &quot;&lt;span id=&quot;Sha512WithBase64&quot;&gt;Sha512WithBase64&lt;/span&gt;&quot;">​</a></h3><p>获取字符串sha512 base64值。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Sha512WithBase64</span><span style="color:#F6F6F4;">(str </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Sha512WithBase64</span><span style="color:#999999;">(</span><span style="color:#393A34;">str </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/q_fY2rA-k5I" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">Sha512WithBase64</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">	fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">	</span><span style="color:#7B7F8B;">// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">Sha512WithBase64</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">	fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">	</span><span style="color:#A0ADA0;">// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GenerateRsaKey" tabindex="-1"><span id="GenerateRsaKey">GenerateRsaKey</span> <a class="header-anchor" href="#GenerateRsaKey" aria-label="Permalink to &quot;&lt;span id=&quot;GenerateRsaKey&quot;&gt;GenerateRsaKey&lt;/span&gt;&quot;">​</a></h3><p>在当前目录下创建rsa私钥文件和公钥文件。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">GenerateRsaKey</span><span style="color:#F6F6F4;">(keySize </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">, priKeyFile, pubKeyFile </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">error</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">GenerateRsaKey</span><span style="color:#999999;">(</span><span style="color:#393A34;">keySize </span><span style="color:#AB5959;">int</span><span style="color:#999999;">,</span><span style="color:#393A34;"> priKeyFile</span><span style="color:#999999;">,</span><span style="color:#393A34;"> pubKeyFile </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/zutRHrDqs0X" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">GenerateRsaKey</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4096</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_private.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_public.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(err)</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">GenerateRsaKey</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4096</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_private.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_public.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">err</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="RsaEncrypt" tabindex="-1"><span id="RsaEncrypt">RsaEncrypt</span> <a class="header-anchor" href="#RsaEncrypt" aria-label="Permalink to &quot;&lt;span id=&quot;RsaEncrypt&quot;&gt;RsaEncrypt&lt;/span&gt;&quot;">​</a></h3><p>用公钥文件ras加密数据。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">RsaEncrypt</span><span style="color:#F6F6F4;">(data []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, pubKeyFileName </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">RsaEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> pubKeyFileName </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/uef0q1fz53I" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">GenerateRsaKey</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4096</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_private.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_public.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">RsaEncrypt</span><span style="color:#F6F6F4;">(data, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_public.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">RsaDecrypt</span><span style="color:#F6F6F4;">(encrypted, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_private.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">GenerateRsaKey</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4096</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_private.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_public.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">RsaEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_public.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">RsaDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_private.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="RsaDecrypt" tabindex="-1"><span id="RsaDecrypt">RsaDecrypt</span> <a class="header-anchor" href="#RsaDecrypt" aria-label="Permalink to &quot;&lt;span id=&quot;RsaDecrypt&quot;&gt;RsaDecrypt&lt;/span&gt;&quot;">​</a></h3><p>用私钥文件rsa解密数据。</p><p><b>函数签名:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">RsaDecrypt</span><span style="color:#F6F6F4;">(data []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, privateKeyFileName </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">byte</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">RsaDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> privateKeyFileName </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/uef0q1fz53I" target="_blank" rel="noreferrer">运行</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">GenerateRsaKey</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">4096</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_private.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_public.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    encrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">RsaEncrypt</span><span style="color:#F6F6F4;">(data, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_public.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    decrypted </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> cryptor.</span><span style="color:#97E1F1;">RsaDecrypt</span><span style="color:#F6F6F4;">(encrypted, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">rsa_private.pem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(decrypted))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/cryptor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">GenerateRsaKey</span><span style="color:#999999;">(</span><span style="color:#2F798A;">4096</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_private.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_public.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">RsaEncrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_public.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">decrypted</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> cryptor</span><span style="color:#999999;">.</span><span style="color:#998418;">RsaDecrypt</span><span style="color:#999999;">(</span><span style="color:#393A34;">encrypted</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">rsa_private.pem</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">decrypted</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,254),g=[t,c,r,y,F,i,d,E,A,u,h];function b(B,f,m,q,D,k){return l(),o("div",null,g)}const S=p(e,[["render",b]]);export{C as __pageData,S as default};
