{"id":905,"date":"2022-08-23T14:57:42","date_gmt":"2022-08-23T06:57:42","guid":{"rendered":"https:\/\/nemo.cool\/?p=905"},"modified":"2024-11-26T15:22:20","modified_gmt":"2024-11-26T07:22:20","slug":"%e8%b0%83%e5%ba%a6%e7%b3%bb%e7%bb%9f%e4%b8%ad%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95%e7%9a%84%e4%bd%bf%e7%94%a8-sm4%e7%ae%97%e6%b3%95%e8%a1%a5%e7%a0%81%e6%a8%a1%e5%bc%8f%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/nemo.cool\/905.html","title":{"rendered":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method"},"content":{"rendered":"<p>\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method<\/p>\n<blockquote>\n<p>\u6570\u636e\u52a0\u5bc6\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7<strong>\u53d8\u6362<\/strong>\u4fe1\u606f\u7684<strong>\u8868\u73b0\u5f62\u5f0f<\/strong>\u6765\u4f2a\u88c5\u9700\u8981\u4fdd\u62a4\u7684\u654f\u611f\u4fe1\u606f\uff0c\u975e\u6388\u6743\u8005\u4e0d\u80fd\u4e86\u89e3\u88ab\u52a0\u5bc6\u7684\u5185\u5bb9\u3002<\/p>\n<\/blockquote>\n<p>\u6839\u636e\u4e1a\u52a1\u573a\u666f\uff0c\u4f7f\u7528\u56fd\u5bc6SM3\/SM4\u52a0\u7b97\u6cd5\u5b9e\u73b0\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\uff0c\u63d0\u9ad8\u6570\u636e\u7684\u53ef\u9760\u6027\uff0c\u6ee1\u8db3\u5ba2\u6237\u573a\u666f\u4e2d\u5176\u4ed6\u7cfb\u7edf\u7684\u63a5\u5165\u6761\u4ef6<\/p>\n<p>\u4f7f\u7528github\u4e0astar\u6700\u591a\u7684https:\/\/github.com\/duanhongyi\/gmssl\uff0c\u4f46\u662f\u8be5\u9879\u76ee\u622a\u6b62\u4f7f\u7528\u65f6\u6682\u672a\u5b9e\u73b00\u586b\u5145\u7b97\u6cd5\uff0c\u540e\u6765\u8865\u9f50\u540ehttps:\/\/github.com\/kanghaov\/gmssl<\/p>\n<p>pr\u7ed9\u5f00\u53d1\u8005\uff0c\u73b0\u5df2\u5b9e\u73b0<\/p>\n<h3>\u901a\u8baf\u534f\u8bae<\/h3>\n<p>\u4e00\u822c\u9009\u5b9a\u52a0\u5bc6\u7684\u901a\u8baf\u534f\u8bae\uff0c\u53cc\u65b9\u7ea6\u5b9a\u54cd\u5e94\u7684\u52a0\u5bc6\u6d41\u7a0b\uff0c\u7b3c\u7edf\u7684\u4f8b\u5b50\uff1a<\/p>\n<p>\u7ea6\u5b9a\u4fe1\u606f\u751f\u6210sign\uff0c\u8fd4\u56detoken\uff0c\u5728token\u6709\u6548\u671f\u5185\u4f5c\u4e3a\u9274\u6743\u6807\u5fd7\uff0c\u6839\u636e\u9700\u8981\u4e5f\u53ef\u4ee5\u4e00\u4e2a\u64cd\u4f5c\u4e3b\u4f53\u4e00\u4e2atoken<\/p>\n<p>1.\u8ba1\u7b97sign<\/p>\n<pre><code class=\"language-python\"># \u5b9a\u5236\u65b9\u63d0\u4f9b\nappId = &quot;1234567890&quot;\nappSecret = &quot;1234567890&quot;\nperson_id = &quot;1234567890&quot;\nencryption_methon() # \u7ea6\u5b9a\u4f7f\u7528sm3\u52a0\u5bc6\n\n# \u8bf7\u6c42\u65b9\u4f7f\u7528\nsign = encryption_methon(appSecret,person_id,timestamp,requestId) # \u751f\u547d\u5468\u671f7200s,<\/code><\/pre>\n<h4>SM3<\/h4>\n<p>\u4f7f\u7528<code>gmssl<\/code>\u7684sm3\u6a21\u5757\u52a0\u5bc6sign\uff0c\u4f8b\u5b50:<\/p>\n<pre><code class=\"language-python\">sign = &#039;00000158ea0a3cef18c45e769f7136de7977db3f0000015815261641523970076F6B86C8FA70AC4CB&#039;\nencoded_sign= sm3.sm3_hash(func.bytes_to_list(bytes(sign, encoding=&quot;ascii&quot;)))<\/code><\/pre>\n<p>\u5c06\u8bf7\u6c42\u4fe1\u606f\u6309\u7167\u9884\u5b9a\u7684\u683c\u5f0f\u751f\u6210\u540e\u4f7f\u7528SM4\u5bf9\u660e\u6587\u8fdb\u884c\u52a0\u5bc6\u540e\u8bf7\u6c42\u670d\u52a1\u7aef<\/p>\n<h4>SM4<\/h4>\n<p>2.\u52a0\u5bc6\u8bf7\u6c42\u6570\u636e\uff1a<\/p>\n<p>\u539f\u6570\u636e\u683c\u5f0f\u4f7f\u7528<code>json.dumps()<\/code>\u53ca<code>bytes()<\/code>\u8f6c\u6362\u6210bytes<\/p>\n<pre><code class=\"language-python\">resData= {&#039;requestId&#039;: &#039;asf0ei8xts9ibvbv809piudtk6qtjkem&#039;, &#039;timestamp&#039;: &#039;1660816878517&#039;, &#039;projectId&#039;: &#039;00001842&#039;, &#039;robotId&#039;: &#039;000018425682&#039;, &#039;sign&#039;: &#039;edcb260f7d2231d695c028362372c705c923d30da7d51892258f6b45d8ad2527&#039;}\nresData = bytes(json.dumps(resData),encoding=&quot;ascii&quot;)<\/code><\/pre>\n<p>\u7531\u4e8e\u8be5\u5ba2\u6237\u8981\u6c42SM4\u52a0\u5bc6\u7b97\u6cd5\u4f7f\u7528<code>ECB\u6a21\u5f0f\u30010\u8865\u7801\u3001utf-8\u7f16\u7801<\/code>\uff0c\u800c\u76ee\u524dgithub\u4e0a\u4e3b\u8981\u7684\u57fa\u4e8epython\u7684SM4\u7b97\u6cd5\u5747\u91c7\u7528<code>PKCS7<\/code>\u8865\u7801\u53ca\u89e3\u7801\uff0c\u9700\u8981\u81ea\u5df1\u8865\u5145<code>0\u8865\u7801<\/code>\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u4e24\u8005\u7684\u533a\u522b\u53ea\u662f\u4ee516byte\u5212\u5206\u6570\u636e\uff0c\u5bf9\u4e8e\u5c3e\u90e8\u4e0d\u6ee116byte\u7684\u6570\u636e\uff0c\u7528[16-\u5c3e\u90e8\u6570\u636e\u957f\u5ea6]\u5b57\u7b26\u8fdb\u884c\u586b\u5145\u8fd8\u662f\u75280\u8fdb\u884c\u586b\u5145\uff0c\u4e0d\u540cpadding\u65b9\u5f0f\uff0c\u52a0\u5bc6\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre><code>pkcs7:\ndata = [34, 123, 92, 34, 114, 101, 113, 117, 101, 115, 116, 73, 100, 92, 34, 58, 32, 92, 34, 101, 97, 48, 97, 51, 99, 101, 102, 49, 56, 99, 52, 53, 101, 55, 54, 57, 102, 55, 49, 51, 54, 100, 101, 55, 57, 55, 55, 100, 98, 51, 102, 92, 34, 44, 32, 92, 34, 115, 105, 103, 110, 92, 34, 58, 32, 92, 34, 97, 101, 50, 98, 97, 56, 49, 49, 48, 49, 57, 99, 55, 49, 49, 50, 101, 98, 56, 101, 55, 52, 100, 50, 54, 53, 99, 55, 51, 52, 98, 48, 53, 101, 97, 55, 54, 49, 102, 56, 56, 50, 56, 99, 101, 50, 102, 54, 101, 102, 50, 98, 100, 99, 54, 100, 49, 100, 50, 54, 100, 53, 51, 50, 92, 34, 44, 32, 92, 34, 114, 111, 98, 111, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 49, 53, 56, 49, 53, 50, 54, 92, 34, 44, 32, 92, 34, 112, 114, 111, 106, 101, 99, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 49, 53, 56, 92, 34, 44, 32, 92, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 92, 34, 58, 32, 92, 34, 49, 54, 52, 49, 53, 50, 51, 57, 55, 48, 48, 55, 54, 92, 34, 125, 34, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11] 240\n\n0:\ndata = [34, 123, 92, 34, 114, 101, 113, 117, 101, 115, 116, 73, 100, 92, 34, 58, 32, 92, 34, 101, 97, 48, 97, 51, 99, 101, 102, 49, 56, 99, 52, 53, 101, 55, 54, 57, 102, 55, 49, 51, 54, 100, 101, 55, 57, 55, 55, 100, 98, 51, 102, 92, 34, 44, 32, 92, 34, 115, 105, 103, 110, 92, 34, 58, 32, 92, 34, 97, 101, 50, 98, 97, 56, 49, 49, 48, 49, 57, 99, 55, 49, 49, 50, 101, 98, 56, 101, 55, 52, 100, 50, 54, 53, 99, 55, 51, 52, 98, 48, 53, 101, 97, 55, 54, 49, 102, 56, 56, 50, 56, 99, 101, 50, 102, 54, 101, 102, 50, 98, 100, 99, 54, 100, 49, 100, 50, 54, 100, 53, 51, 50, 92, 34, 44, 32, 92, 34, 114, 111, 98, 111, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 49, 53, 56, 49, 53, 50, 54, 92, 34, 44, 32, 92, 34, 112, 114, 111, 106, 101, 99, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 49, 53, 56, 92, 34, 44, 32, 92, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 92, 34, 58, 32, 92, 34, 49, 54, 52, 49, 53, 50, 51, 57, 55, 48, 48, 55, 54, 92, 34, 125, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]<\/code><\/pre>\n<p>\u6e90\u4ee3\u7801\u4e2d<code>gmssl\/func.py<\/code>\uff1a<\/p>\n<pre><code class=\"language-python\">padding = lambda data, block=16: data + [(16 - len(data) % block)for _ in range(16 - len(data) % block)]\nunpadding = lambda data: data[:-data[-1]]<\/code><\/pre>\n<p>\u65b0\u589e<code>0\u8865\u7801<\/code>\uff0c\u4e3a\uff1a<\/p>\n<pre><code class=\"language-python\">pkcs7_padding = lambda data, block=16: data + [(16 - len(data) % block)for _ in range(16 - len(data) % block)]\n\nzero_padding = lambda data, block=16: data + [0 for _ in range(16 - len(data) % block)]\n\npkcs7_unpadding = lambda data: data[:-data[-1]]\n\nzero_unpadding = lambda data,i =1:data[:-i] if data[-i] == 0 else i+1\n<\/code><\/pre>\n<p>\u9009\u62e9\u4e0d\u540c\u8865\u7801\u65b9\u5f0f\u53ea\u9700\u8981\u5728<code>SM4<\/code>\u6a21\u5757\u4e2dSM4\u7c7b\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u4f20\u53c2\u8fdb\u53bb\u5c31\u597d\u4e86<\/p>\n<p>\u4ed3\u5e93\u5730\u5740\uff1a<\/p>\n<div class=\"mdx-github-cot\" data-mdxgithuba=\"kanghaov\" data-mdxgithubp=\"gmssl\" data-mdxgithubg=\"https:\/\/api.github.com\/\"><div class=\"mdx-github-wait-out-c2\"><div class=\"mdx-github-wait-out-c mdui-valign\"><div class=\"mdx-github-wait-out\"><div class=\"mdx-github-wait\"><a href=\"https:\/\/github.com\/kanghaov\/gmssl\"><div class=\"mdui-spinner\"><\/div><\/a><\/div><\/div><\/div><\/div><\/div>\n<p>3.\u89e3\u5bc6\u8fd4\u56de\u6570\u636e<\/p>\n<p>\u76f4\u63a5\u8c03\u7528\u76f8\u5173\u51fd\u6570\uff0c\u9009\u62e9<code>0\u586b\u5145<\/code>\u65b9\u5f0f\u4f1a\u81ea\u52a8\u9009\u62e9\u54cd\u5e94\u7684\u89e3\u7801\u65b9\u5f0f\uff0c\u89e3\u5bc6\u540e\uff1a<\/p>\n<pre><code class=\"language-python\">{\n    &quot;data&quot;: {\n        &quot;token&quot;: &quot;xAeTiWxw99Eg7QBm5qR6fIGDmrcaaUtLzlZ2zpOl0HKcvV6MYZiiW5e+ThvBzIy8&quot;\n    },\n    &quot;msg&quot;: &quot;\u6210\u529f&quot;,\n    &quot;msgCode&quot;: 0,\n    &quot;requestId&quot;: &quot;ea0a3cef18c45e769f7136de7977db3f&quot;,\n    &quot;sign&quot;: &quot;d81840ab9ec6a97085afe1bee085f6e0fea2c38ba4d65b5936abcaabc079c6c9&quot;,\n    &quot;success&quot;: true,\n    &quot;timestamp&quot;: &quot;1641868606481&quot;\n}<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u83b7\u53d6\u4e86\u8bf7\u6c42\u5bf9\u8c61\u4e13\u5c5e\u7684token\uff0c\u540e\u7eed\u8bf7\u6c42\u65f6\uff0c\u76f8\u5e94\u7684\u8bf7\u6c42\u4e3b\u4f53\u9644\u5e26\u4e0atoken\u548cencryptScript\u4fe1\u606f\u5c31\u597d\u4e86<\/p>\n<p>\u53e6\uff1a<\/p>\n<p>\u76f8\u6bd4\u4e8e\u4f7f\u7528python\u5185\u7f6e\u7684\u6570\u636e\u7ed3\u6784\uff0c\u67d0\u4e9b\u573a\u666f\u66f4\u559c\u6b22\u4f7f\u7528<code>class<\/code>\u642d\u914d<code>__repe__<\/code>\u65b9\u6cd5\u5b9e\u73b0\u6570\u636e\u7684\u5b58\u50a8\uff0c\u6bd4\u5982:<\/p>\n<pre><code class=\"language-python\">class appInfo:\n    &quot;&quot;&quot;\n    \u5f00\u53d1\u8005\u4fe1\u606f\n    &quot;&quot;&quot;\n\n    def __init__(self, appId=&quot;&quot;, appSecret=&quot;&quot;, getTime=&quot;&quot;):\n        self.appId = appId\n        self.appSecret = bytes(appSecret, encoding=&quot;ascii&quot;)\n        self.appSecretStr = appSecret\n        self.getTime = getTime\n\n    def __repr__(self):\n        return &quot;appId = {0},appSecret={1},appSecretStr={2},getTime={3}&quot;.format(\n            str(self.appId),self.appSecret,str(self.appSecretStr),str(self.getTime))<\/code><\/pre>\n<p>\u53ef\u4ee5\u5bf9\u6570\u636e\u6709\u66f4\u591a\u7684\u5904\u7406\u65b9\u5f0f<\/p>\n<hr \/>\n<blockquote>\n<p>The basic idea of data encryption is to disguise the sensitive information to be protected by <strong>transforming<\/strong> the <strong>manifestation<\/strong> of information, so that unauthorized persons cannot understand the encrypted content.<\/p>\n<\/blockquote>\n<p>According to the business scenario, we use SM3\/SM4 encryption algorithm to realize the security of data transmission, improve the reliability of data, and meet the access conditions of other systems in the customer scenario<\/p>\n<p>Use <a href=\"https:\/\/github.com\/duanhongyi\/gmssl\">https:\/\/github.com\/duanhongyi\/gmssl<\/a> which has the most stars on github, but the project has not implemented the 0-fill algorithm as of the time of use, and then <a href=\"https:\/\/github.com\/kanghaov\/gmssl\">https:\/\/github.com\/kanghaov\/gmssl<\/a><\/p>\n<p>pr to the developer, now realized<\/p>\n<h3>Communication protocol<\/h3>\n<p>Generally selected encryption communication protocol, both sides agree on the encryption process of the response, generalized example.<\/p>\n<p>The agreed information generates a sign, returns a token, which is used as a forensic marker during the validity of the token, and can also be an operation subject a token as needed<\/p>\n<ol>\n<li>Calculate sign<\/li>\n<\/ol>\n<pre><code class=\"language-python\"># provided by the customizer\nappId = &quot;1234567890&quot;\nappSecret = &quot;1234567890&quot;\nperson_id = &quot;1234567890&quot;\nencryption_methon() # covenant to use sm3 encryption\n\n# The requesting party uses\nsign = encryption_methon(appSecret,person_id,timestamp,requestId) # Lifecycle 7200s,<\/code><\/pre>\n<h4>SM3<\/h4>\n<p>Use the sm3 module of <code>gmssl<\/code> to encrypt the sign, example:<\/p>\n<pre><code class=\"language-python\">sign = &#039;0000000158ea0a3cef18c45e769f7136de7977db3f0000015815261641523970076F6B86C8FA70AC4CB&#039;\nencoded_sign= sm3.sm3_hash(func.bytes_to_list(bytes(sign, encoding=&quot;ascii&quot;)))<\/code><\/pre>\n<p>After generating the request message in the predefined format, use SM4 to encrypt the plaintext and request the server side<\/p>\n<h4>SM4<\/h4>\n<ol start=\"2\">\n<li>Encrypt the request data.<\/li>\n<\/ol>\n<p>The original data format is converted to bytes using <code>json.dumps()<\/code> and <code>bytes()<\/code>.<\/p>\n<pre><code class=\"language-python\">resData= {&#039;requestId&#039;: &#039;asf0ei8xts9ibvbv809piudtk6qtjkem&#039;, &#039;timestamp&#039;: &#039;1660816878517&#039;, &#039;projectId&#039;: &#039;00001842&#039;, &#039;robotId&#039;: &#039;000018425682 &#039;, &#039;sign&#039;: &#039;edcb260f7d2231d695c028362372c705c923d30da7d51892258f6b45d8ad2527&#039;}\nresData = bytes(json.dumps(resData),encoding=&quot;ascii&quot;)<\/code><\/pre>\n<p>Since the customer requires SM4 encryption algorithm to use <code>ECB mode, 0 complement, utf-8 encoding<\/code>, and the main python-based SM4 algorithms on github currently use <code>PKCS7<\/code> complement and decoding, you need to add your own <code>0 complement<\/code> implementation, the difference between the two is only to divide the data by 16byte, for the tail is less than 16byte data , padding with [16 &#8211; tail data length] characters or padding with 0, different padding methods, the encryption results are as follows.<\/p>\n<pre><code>pkcs7:\ndata = [34, 123, 92, 34, 114, 101, 113, 117, 101, 115, 116, 73, 100, 92, 34, 58, 32, 92, 34, 101, 97, 48, 97, 51, 99, 101, 102, 49, 56, 99, 52, 53, 101, 55, 54, 57, 102 , 55, 49, 51, 54, 100, 101, 55, 57, 55, 55, 100, 98, 51, 102, 92, 34, 44, 32, 92, 34, 115, 105, 103, 110, 92, 34, 58, 32, 92, 34, 97, 101, 50, 98, 97, 56, 49, 49, 48, 49, 57, 99, 55, 49, 49, 50, 101, 98, 56, 101, 55, 52, 100, 50, 54, 53, 99, 55, 51, 52, 98, 48, 53, 101, 97, 55, 54, 49, 102, 56, 56, 50, 56, 99, 101, 50, 102, 54, 101, 102, 50, 98, 100, 99, 54, 100, 49, 100, 50, 54, 100, 53, 51, 50, 92, 34, 44, 32, 92, 34, 114, 111, 98, 111, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 49, 53, 56, 49, 53, 50, 54, 92, 34, 44, 32, 92, 34, 112, 114, 111, 106, 101, 99, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 48, 49, 53, 56, 92, 34, 44, 32, 92, 34, 116 , 105, 109, 101, 115, 116, 97, 109, 112, 92, 34, 58, 32, 92, 34, 49, 54, 52, 49, 53, 50, 51, 57, 55, 48, 48, 55, 54, 92, 34, 125, 34, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11] 240\n\n0:\ndata = [34, 123, 92, 34, 114, 101, 113, 117, 101, 115, 116, 73, 100, 92, 34, 58, 32, 92, 34, 101, 97, 48, 97, 51, 99, 101, 102, 49, 56, 99, 52, 53, 101, 55, 54, 57, 102 , 55, 49, 51, 54, 100, 101, 55, 57, 55, 55, 100, 98, 51, 102, 92, 34, 44, 32, 92, 34, 115, 105, 103, 110, 92, 34, 58, 32, 92, 34, 97, 101, 50, 98, 97, 56, 49, 49, 48, 49, 57, 99, 55, 49, 49, 50, 101, 98, 56, 101, 55, 52, 100, 50, 54, 53, 99, 55, 51, 52, 98, 48, 53, 101, 97, 55, 54, 49, 102, 56, 56, 50, 56, 99, 101, 50, 102, 54, 101, 102, 50, 98, 100, 99, 54, 100, 49, 100, 50, 54, 100, 53, 51, 50, 92, 34, 44, 32, 92, 34, 114, 111, 98, 111, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 49, 53, 56, 49, 53, 50, 54, 92, 34, 44, 32, 92, 34, 112, 114, 111, 106, 101, 99, 116, 73, 100, 92, 34, 58, 32, 92, 34, 48, 48, 48, 48, 48, 48, 49, 53, 56, 92, 34, 44, 32, 92, 34, 116 , 105, 109, 101, 115, 116, 97, 109, 112, 92, 34, 58, 32, 92, 34, 49, 54, 52, 49, 53, 50, 51, 57, 55, 48, 48, 55, 54, 92, 34, 125, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]<\/code><\/pre>\n<p>Source code in <code>gmssl\/func.py<\/code>.<\/p>\n<pre><code class=\"language-python\">padding = lambda data, block=16: data + [(16 - len(data) % block) for _ in range(16 - len(data) % block)]\nunpadding = lambda data: data[:-data[-1]]<\/code><\/pre>\n<p>Add <code><code>0-complement<\/code><\/code> as<\/p>\n<pre><code class=\"language-python\">pkcs7_padding = lambda data, block=16: data + [(16 - len(data) % block) for _ in range(16 - len(data) % block)]\n\nzero_padding = lambda data, block=16: data + [0 for _ in range(16 - len(data) % block)]\n\npkcs7_unpadding = lambda data: data[:-data[-1]]\n\nzero_unpadding = lambda data,i =1:data[:-i] if data[-i] == 0 else i+1\n<\/code><\/pre>\n<p>Choosing a different complement method is just a matter of passing in a reference when the SM4 class is instantiated in the <code>SM4<\/code> module<\/p>\n<p>Repository address.<\/p>\n<div class=\"mdx-github-cot\" data-mdxgithuba=\"kanghaov\" data-mdxgithubp=\"gmssl\" data-mdxgithubg=\"https:\/\/api.github.com\/\"><div class=\"mdx-github-wait-out-c2\"><div class=\"mdx-github-wait-out-c mdui-valign\"><div class=\"mdx-github-wait-out\"><div class=\"mdx-github-wait\"><a href=\"https:\/\/github.com\/kanghaov\/gmssl\"><div class=\"mdui-spinner\"><\/div><\/a><\/div><\/div><\/div><\/div><\/div>\n<ol start=\"3\">\n<li>Decrypt the returned data<\/li>\n<\/ol>\n<p>Directly call the relevant function, select <code><code>0 fill<\/code><\/code> method will automatically select the response decoding method, after decrypting.<\/p>\n<pre><code class=\"language-python\">{\n    &quot;data&quot;: {\n        &quot;token&quot;: &quot;xAeTiWxw99Eg7QBm5qR6fIGDmrcaaUtLzlZ2zpOl0HKcvV6MYZiiW5e+ThvBzIy8&quot;\n    },\n    &quot;msg&quot;: &quot;Success&quot;,\n    &quot;msgCode&quot;: 0,\n    &quot;requestId&quot;: &quot;ea0a3cef18c45e769f7136de7977db3f&quot;,\n    &quot;sign&quot;: &quot;d81840ab9ec6a97085afe1bee085f6e0fea2c38ba4d65b5936abcaabc079c6c9&quot;,\n    &quot;success&quot;: true,\n    &quot;timestamp&quot;: &quot;1641868606481&quot;\n}<\/code><\/pre>\n<p>This will get the request object exclusive token, subsequent requests, the corresponding request body with the token and encryptScript information on the good<\/p>\n<p>Also.<\/p>\n<p>Rather than using python&#8217;s built-in data structures, some scenarios prefer to use <code>class<\/code> with <code>__repe__<\/code> methods to achieve data storage, such as:<\/p>\n<pre><code class=\"language-python\">class appInfo:\n    &quot;&quot;&quot;\n    \u5f00\u53d1\u8005\u4fe1\u606f\n    &quot;&quot;&quot;\n\n    def __init__(self, appId=&quot;&quot;, appSecret=&quot;&quot;, getTime=&quot;&quot;):\n        self.appId = appId\n        self.appSecret = bytes(appSecret, encoding=&quot;ascii&quot;)\n        self.appSecretStr = appSecret\n        self.getTime = getTime\n\n    def __repr__(self):\n        return &quot;appId = {0},appSecret={1},appSecretStr={2},getTime={3}&quot;.format(\n            str(self.appId),self.appSecret,str(self.appSecretStr),str(self.getTime))<\/code><\/pre>\n<p>You can have more ways to handle data<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method \u6570\u636e\u52a0\u5bc6\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u53d8\u6362\u4fe1\u606f\u7684\u8868\u73b0\u5f62\u5f0f\u6765\u4f2a\u88c5\u9700\u8981\u4fdd\u62a4\u7684\u654f\u611f\u4fe1\u606f\uff0c\u975e\u6388\u6743\u8005\u4e0d\u80fd\u4e86\u89e3\u88ab\u52a0\u5bc6\u7684\u5185\u5bb9\u3002 \u6839\u636e\u4e1a\u52a1\u573a\u666f\uff0c\u4f7f\u7528\u56fd\u5bc6SM3\/SM4\u52a0\u7b97\u6cd5\u5b9e\u73b0\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\uff0c\u63d0\u9ad8\u6570\u636e\u7684\u53ef\u9760\u6027\uff0c\u6ee1\u8db3\u5ba2\u6237\u573a\u666f\u4e2d\u5176\u4ed6\u7cfb\u7edf\u7684\u63a5\u5165\u6761\u4ef6 \u4f7f\u7528github\u4e0astar\u6700\u591a\u7684https:\/\/github.com\/duanhongyi\/gmssl\uff0c\u4f46\u662f\u8be5\u9879\u76ee\u622a\u6b62\u4f7f\u7528\u65f6\u6682\u672a\u5b9e\u73b00\u586b\u5145\u7b97\u6cd5\uff0c\u540e\u6765\u8865\u9f50\u540ehttps:\/\/github.com\/kanghaov\/gmssl pr\u7ed9\u5f00\u53d1\u8005\uff0c\u73b0\u5df2\u5b9e\u73b0 \u901a\u8baf\u534f\u8bae \u4e00\u822c\u9009\u5b9a\u52a0\u5bc6\u7684\u901a\u8baf\u534f\u8bae\uff0c\u53cc\u65b9\u7ea6\u5b9a\u54cd\u5e94\u7684\u52a0\u5bc6\u6d41\u7a0b\uff0c\u7b3c\u7edf\u7684\u4f8b\u5b50\uff1a \u7ea6\u5b9a\u4fe1\u606f\u751f\u6210sign\uff0c\u8fd4\u56detoken\uff0c\u5728token\u6709\u6548\u671f\u5185\u4f5c\u4e3a\u9274\u6743\u6807\u5fd7\uff0c\u6839\u636e\u9700\u8981\u4e5f\u53ef\u4ee5\u4e00\u4e2a\u64cd\u4f5c\u4e3b\u4f53\u4e00\u4e2atoken 1.\u8ba1\u7b97sign # \u5b9a\u5236\u65b9\u63d0\u4f9b appId = &quot;1234567890&quot; appSecret = &quot;1234567890&quot; person_id = &quot;1234567890&quot; encryption_methon() # \u7ea6\u5b9a\u4f7f\u7528sm3\u52a0\u5bc6 # \u8bf7\u6c42\u65b9\u4f7f\u7528 sign = encryption_methon(appSecret,person_id,timestamp,requestId) # \u751f\u547d\u5468\u671f7200s, SM3 \u4f7f\u7528gmssl\u7684sm3\u6a21\u5757\u52a0\u5bc6sign\uff0c\u4f8b\u5b50: sign = &#039;00000158ea0a3cef18c45e769f7136de7977db3f0000015815261641523970076F6B86C8FA70AC4CB&#039; encoded_sign= sm3.sm3_hash(func.bytes_to_list(bytes(sign, encoding=&quot;ascii&quot;))) \u5c06\u8bf7\u6c42\u4fe1\u606f\u6309\u7167\u9884\u5b9a\u7684\u683c\u5f0f\u751f\u6210\u540e\u4f7f\u7528SM4\u5bf9\u660e\u6587\u8fdb\u884c\u52a0\u5bc6\u540e\u8bf7\u6c42\u670d\u52a1\u7aef SM4 2.\u52a0\u5bc6\u8bf7\u6c42\u6570\u636e\uff1a \u539f\u6570\u636e\u683c\u5f0f\u4f7f\u7528json.dumps()\u53cabytes()\u8f6c\u6362\u6210bytes resData= {&#039;requestId&#039;: &#039;asf0ei8xts9ibvbv809piudtk6qtjkem&#039;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":906,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86,75,2],"tags":[111,112,89],"class_list":["post-905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","category-linux","category-py","tag-sm4","tag-112","tag-89"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method - Nemo<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nemo.cool\/905.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method - Nemo\" \/>\n<meta property=\"og:description\" content=\"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method \u6570\u636e\u52a0\u5bc6\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u53d8\u6362\u4fe1\u606f\u7684\u8868\u73b0\u5f62\u5f0f\u6765\u4f2a\u88c5\u9700\u8981\u4fdd\u62a4\u7684\u654f\u611f\u4fe1\u606f\uff0c\u975e\u6388\u6743\u8005\u4e0d\u80fd\u4e86\u89e3\u88ab\u52a0\u5bc6\u7684\u5185\u5bb9\u3002 \u6839\u636e\u4e1a\u52a1\u573a\u666f\uff0c\u4f7f\u7528\u56fd\u5bc6SM3\/SM4\u52a0\u7b97\u6cd5\u5b9e\u73b0\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\uff0c\u63d0\u9ad8\u6570\u636e\u7684\u53ef\u9760\u6027\uff0c\u6ee1\u8db3\u5ba2\u6237\u573a\u666f\u4e2d\u5176\u4ed6\u7cfb\u7edf\u7684\u63a5\u5165\u6761\u4ef6 \u4f7f\u7528github\u4e0astar\u6700\u591a\u7684https:\/\/github.com\/duanhongyi\/gmssl\uff0c\u4f46\u662f\u8be5\u9879\u76ee\u622a\u6b62\u4f7f\u7528\u65f6\u6682\u672a\u5b9e\u73b00\u586b\u5145\u7b97\u6cd5\uff0c\u540e\u6765\u8865\u9f50\u540ehttps:\/\/github.com\/kanghaov\/gmssl pr\u7ed9\u5f00\u53d1\u8005\uff0c\u73b0\u5df2\u5b9e\u73b0 \u901a\u8baf\u534f\u8bae \u4e00\u822c\u9009\u5b9a\u52a0\u5bc6\u7684\u901a\u8baf\u534f\u8bae\uff0c\u53cc\u65b9\u7ea6\u5b9a\u54cd\u5e94\u7684\u52a0\u5bc6\u6d41\u7a0b\uff0c\u7b3c\u7edf\u7684\u4f8b\u5b50\uff1a \u7ea6\u5b9a\u4fe1\u606f\u751f\u6210sign\uff0c\u8fd4\u56detoken\uff0c\u5728token\u6709\u6548\u671f\u5185\u4f5c\u4e3a\u9274\u6743\u6807\u5fd7\uff0c\u6839\u636e\u9700\u8981\u4e5f\u53ef\u4ee5\u4e00\u4e2a\u64cd\u4f5c\u4e3b\u4f53\u4e00\u4e2atoken 1.\u8ba1\u7b97sign # \u5b9a\u5236\u65b9\u63d0\u4f9b appId = &quot;1234567890&quot; appSecret = &quot;1234567890&quot; person_id = &quot;1234567890&quot; encryption_methon() # \u7ea6\u5b9a\u4f7f\u7528sm3\u52a0\u5bc6 # \u8bf7\u6c42\u65b9\u4f7f\u7528 sign = encryption_methon(appSecret,person_id,timestamp,requestId) # \u751f\u547d\u5468\u671f7200s, SM3 \u4f7f\u7528gmssl\u7684sm3\u6a21\u5757\u52a0\u5bc6sign\uff0c\u4f8b\u5b50: sign = &#039;00000158ea0a3cef18c45e769f7136de7977db3f0000015815261641523970076F6B86C8FA70AC4CB&#039; encoded_sign= sm3.sm3_hash(func.bytes_to_list(bytes(sign, encoding=&quot;ascii&quot;))) \u5c06\u8bf7\u6c42\u4fe1\u606f\u6309\u7167\u9884\u5b9a\u7684\u683c\u5f0f\u751f\u6210\u540e\u4f7f\u7528SM4\u5bf9\u660e\u6587\u8fdb\u884c\u52a0\u5bc6\u540e\u8bf7\u6c42\u670d\u52a1\u7aef SM4 2.\u52a0\u5bc6\u8bf7\u6c42\u6570\u636e\uff1a \u539f\u6570\u636e\u683c\u5f0f\u4f7f\u7528json.dumps()\u53cabytes()\u8f6c\u6362\u6210bytes resData= {&#039;requestId&#039;: &#039;asf0ei8xts9ibvbv809piudtk6qtjkem&#039;, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nemo.cool\/905.html\" \/>\n<meta property=\"og:site_name\" content=\"Nemo\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-23T06:57:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-26T07:22:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/nemo.cool\/wp-content\/uploads\/2022\/08\/markus-winkler-SZ98vfIx0pw-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"427\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nemo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nemo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html\"},\"author\":{\"name\":\"Nemo\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"headline\":\"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\\\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\\\/Use of encryption algorithms in scheduling systems\\\/add SM4 complementary 0 method\",\"datePublished\":\"2022-08-23T06:57:42+00:00\",\"dateModified\":\"2024-11-26T07:22:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html\"},\"wordCount\":457,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"image\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/markus-winkler-SZ98vfIx0pw-unsplash.jpg\",\"keywords\":[\"SM4\",\"\u52a0\u5bc6\u7b97\u6cd5\",\"\u8c03\u5ea6\"],\"articleSection\":[\"Dev\",\"Linux\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nemo.cool\\\/905.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html\",\"url\":\"https:\\\/\\\/nemo.cool\\\/905.html\",\"name\":\"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\\\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\\\/Use of encryption algorithms in scheduling systems\\\/add SM4 complementary 0 method - Nemo\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/markus-winkler-SZ98vfIx0pw-unsplash.jpg\",\"datePublished\":\"2022-08-23T06:57:42+00:00\",\"dateModified\":\"2024-11-26T07:22:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nemo.cool\\\/905.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#primaryimage\",\"url\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/markus-winkler-SZ98vfIx0pw-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/markus-winkler-SZ98vfIx0pw-unsplash.jpg\",\"width\":640,\"height\":427},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/905.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\\\/\\\/nemo.cool\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\\\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\\\/Use of encryption algorithms in scheduling systems\\\/add SM4 complementary 0 method\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/#website\",\"url\":\"https:\\\/\\\/nemo.cool\\\/\",\"name\":\"Nemo\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nemo.cool\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\",\"name\":\"Nemo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"url\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"caption\":\"Nemo\"},\"logo\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\"},\"sameAs\":[\"https:\\\/\\\/nemo.cool\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method - Nemo","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nemo.cool\/905.html","og_locale":"en_US","og_type":"article","og_title":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method - Nemo","og_description":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method \u6570\u636e\u52a0\u5bc6\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u53d8\u6362\u4fe1\u606f\u7684\u8868\u73b0\u5f62\u5f0f\u6765\u4f2a\u88c5\u9700\u8981\u4fdd\u62a4\u7684\u654f\u611f\u4fe1\u606f\uff0c\u975e\u6388\u6743\u8005\u4e0d\u80fd\u4e86\u89e3\u88ab\u52a0\u5bc6\u7684\u5185\u5bb9\u3002 \u6839\u636e\u4e1a\u52a1\u573a\u666f\uff0c\u4f7f\u7528\u56fd\u5bc6SM3\/SM4\u52a0\u7b97\u6cd5\u5b9e\u73b0\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\uff0c\u63d0\u9ad8\u6570\u636e\u7684\u53ef\u9760\u6027\uff0c\u6ee1\u8db3\u5ba2\u6237\u573a\u666f\u4e2d\u5176\u4ed6\u7cfb\u7edf\u7684\u63a5\u5165\u6761\u4ef6 \u4f7f\u7528github\u4e0astar\u6700\u591a\u7684https:\/\/github.com\/duanhongyi\/gmssl\uff0c\u4f46\u662f\u8be5\u9879\u76ee\u622a\u6b62\u4f7f\u7528\u65f6\u6682\u672a\u5b9e\u73b00\u586b\u5145\u7b97\u6cd5\uff0c\u540e\u6765\u8865\u9f50\u540ehttps:\/\/github.com\/kanghaov\/gmssl pr\u7ed9\u5f00\u53d1\u8005\uff0c\u73b0\u5df2\u5b9e\u73b0 \u901a\u8baf\u534f\u8bae \u4e00\u822c\u9009\u5b9a\u52a0\u5bc6\u7684\u901a\u8baf\u534f\u8bae\uff0c\u53cc\u65b9\u7ea6\u5b9a\u54cd\u5e94\u7684\u52a0\u5bc6\u6d41\u7a0b\uff0c\u7b3c\u7edf\u7684\u4f8b\u5b50\uff1a \u7ea6\u5b9a\u4fe1\u606f\u751f\u6210sign\uff0c\u8fd4\u56detoken\uff0c\u5728token\u6709\u6548\u671f\u5185\u4f5c\u4e3a\u9274\u6743\u6807\u5fd7\uff0c\u6839\u636e\u9700\u8981\u4e5f\u53ef\u4ee5\u4e00\u4e2a\u64cd\u4f5c\u4e3b\u4f53\u4e00\u4e2atoken 1.\u8ba1\u7b97sign # \u5b9a\u5236\u65b9\u63d0\u4f9b appId = &quot;1234567890&quot; appSecret = &quot;1234567890&quot; person_id = &quot;1234567890&quot; encryption_methon() # \u7ea6\u5b9a\u4f7f\u7528sm3\u52a0\u5bc6 # \u8bf7\u6c42\u65b9\u4f7f\u7528 sign = encryption_methon(appSecret,person_id,timestamp,requestId) # \u751f\u547d\u5468\u671f7200s, SM3 \u4f7f\u7528gmssl\u7684sm3\u6a21\u5757\u52a0\u5bc6sign\uff0c\u4f8b\u5b50: sign = &#039;00000158ea0a3cef18c45e769f7136de7977db3f0000015815261641523970076F6B86C8FA70AC4CB&#039; encoded_sign= sm3.sm3_hash(func.bytes_to_list(bytes(sign, encoding=&quot;ascii&quot;))) \u5c06\u8bf7\u6c42\u4fe1\u606f\u6309\u7167\u9884\u5b9a\u7684\u683c\u5f0f\u751f\u6210\u540e\u4f7f\u7528SM4\u5bf9\u660e\u6587\u8fdb\u884c\u52a0\u5bc6\u540e\u8bf7\u6c42\u670d\u52a1\u7aef SM4 2.\u52a0\u5bc6\u8bf7\u6c42\u6570\u636e\uff1a \u539f\u6570\u636e\u683c\u5f0f\u4f7f\u7528json.dumps()\u53cabytes()\u8f6c\u6362\u6210bytes resData= {&#039;requestId&#039;: &#039;asf0ei8xts9ibvbv809piudtk6qtjkem&#039;, [&hellip;]","og_url":"https:\/\/nemo.cool\/905.html","og_site_name":"Nemo","article_published_time":"2022-08-23T06:57:42+00:00","article_modified_time":"2024-11-26T07:22:20+00:00","og_image":[{"width":640,"height":427,"url":"https:\/\/nemo.cool\/wp-content\/uploads\/2022\/08\/markus-winkler-SZ98vfIx0pw-unsplash.jpg","type":"image\/jpeg"}],"author":"Nemo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nemo","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nemo.cool\/905.html#article","isPartOf":{"@id":"https:\/\/nemo.cool\/905.html"},"author":{"name":"Nemo","@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"headline":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method","datePublished":"2022-08-23T06:57:42+00:00","dateModified":"2024-11-26T07:22:20+00:00","mainEntityOfPage":{"@id":"https:\/\/nemo.cool\/905.html"},"wordCount":457,"commentCount":0,"publisher":{"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"image":{"@id":"https:\/\/nemo.cool\/905.html#primaryimage"},"thumbnailUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2022\/08\/markus-winkler-SZ98vfIx0pw-unsplash.jpg","keywords":["SM4","\u52a0\u5bc6\u7b97\u6cd5","\u8c03\u5ea6"],"articleSection":["Dev","Linux","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nemo.cool\/905.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nemo.cool\/905.html","url":"https:\/\/nemo.cool\/905.html","name":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method - Nemo","isPartOf":{"@id":"https:\/\/nemo.cool\/#website"},"primaryImageOfPage":{"@id":"https:\/\/nemo.cool\/905.html#primaryimage"},"image":{"@id":"https:\/\/nemo.cool\/905.html#primaryimage"},"thumbnailUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2022\/08\/markus-winkler-SZ98vfIx0pw-unsplash.jpg","datePublished":"2022-08-23T06:57:42+00:00","dateModified":"2024-11-26T07:22:20+00:00","breadcrumb":{"@id":"https:\/\/nemo.cool\/905.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nemo.cool\/905.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nemo.cool\/905.html#primaryimage","url":"https:\/\/nemo.cool\/wp-content\/uploads\/2022\/08\/markus-winkler-SZ98vfIx0pw-unsplash.jpg","contentUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2022\/08\/markus-winkler-SZ98vfIx0pw-unsplash.jpg","width":640,"height":427},{"@type":"BreadcrumbList","@id":"https:\/\/nemo.cool\/905.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/nemo.cool\/"},{"@type":"ListItem","position":2,"name":"\u8c03\u5ea6\u7cfb\u7edf\u4e2d\u52a0\u5bc6\u7b97\u6cd5\u7684\u4f7f\u7528\/\u589e\u52a0SM4\u88650\u65b9\u6cd5\/Use of encryption algorithms in scheduling systems\/add SM4 complementary 0 method"}]},{"@type":"WebSite","@id":"https:\/\/nemo.cool\/#website","url":"https:\/\/nemo.cool\/","name":"Nemo","description":"","publisher":{"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nemo.cool\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2","name":"Nemo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","url":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","contentUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","caption":"Nemo"},"logo":{"@id":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg"},"sameAs":["https:\/\/nemo.cool"]}]}},"_links":{"self":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts\/905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/comments?post=905"}],"version-history":[{"count":0,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts\/905\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/media\/906"}],"wp:attachment":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/media?parent=905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/categories?post=905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/tags?post=905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}