{"id":2234,"date":"2023-11-10T18:01:44","date_gmt":"2023-11-10T10:01:44","guid":{"rendered":"https:\/\/bianchenghao6.com\/2234.html"},"modified":"2023-11-10T18:02:52","modified_gmt":"2023-11-10T10:02:52","slug":"%e5%8c%ba%e5%9d%97%e9%93%be%e5%ae%a2%e6%88%b7%e7%ab%af%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/2234.html","title":{"rendered":"\u533a\u5757\u94fe\u5ba2\u6237\u7aef\u7c7b"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

\u533a\u5757\u94fe\u5ba2\u6237\u7aef\u7c7b<\/h1>\n

Python\u533a\u5757\u94fe\u5ba2\u6237\u7aef\u7c7b\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n

\n Client <\/b>\u7c7b\u4f7f\u7528\u5185\u7f6e\u7684Python
\n RSA <\/b>\u7b97\u6cd5\u751f\u6210
\n private <\/b>\u548c
\n public <\/b>\u5bc6\u94a5\u3002\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u53c2\u8003
\n \u672c\u6559\u7a0b<\/b>\u6765\u4e86\u89e3RSA\u7684\u5b9e\u73b0\u3002\u5728\u5bf9\u8c61\u521d\u59cb\u5316\u671f\u95f4\uff0c\u6211\u4eec\u521b\u5efa\u79c1\u94a5\u548c\u516c\u94a5\u5e76\u5c06\u5176\u503c\u5b58\u50a8\u5728\u5b9e\u4f8b\u53d8\u91cf\u4e2d\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
self._private_key = RSA.generate<\/span>(1024, random)
self._public_key = self._private_key.publickey<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bf7\u6ce8\u610f\uff0c\u60a8\u7edd\u4e0d\u8981\u4e22\u5931\u79c1\u94a5\u3002\u4e3a\u4e86\u4fdd\u6301\u8bb0\u5f55\uff0c\u53ef\u4ee5\u5c06\u751f\u6210\u7684\u79c1\u94a5\u590d\u5236\u5230\u5b89\u5168\u7684\u5916\u90e8\u5b58\u50a8\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u5c06\u5176ASCII\u8868\u793a\u7b80\u5355\u5730\u5199\u5728\u4e00\u5f20\u7eb8\u4e0a\u3002\n <\/div>\n
\n \u751f\u6210\u7684
\n \u516c\u5171<\/b>\u5bc6\u94a5\u5c06\u7528\u4f5c\u5ba2\u6237\u7684\u8eab\u4efd\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a
\n identity <\/b>\u7684\u5c5e\u6027\uff0c\u8be5\u5c5e\u6027\u8fd4\u56de\u516c\u94a5\u7684HEX\u8868\u793a\u5f62\u5f0f\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
@property
   def <\/span>identity(self):
      return
binascii.hexlify<\/span>(self._public_key.exportKey<\/span>(format='DER'<\/span>))
.decode<\/span>('ascii'<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8eab\u4efd<\/b>\u5bf9\u4e8e\u6bcf\u4e2a\u5ba2\u6237\u800c\u8a00\u90fd\u662f\u552f\u4e00\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u516c\u5f00\u4f7f\u7528\u3002\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u4f7f\u7528\u6b64
\n \u8eab\u4efd<\/b>\u5411\u60a8\u53d1\u9001\u865a\u62df\u8d27\u5e01\uff0c\u8be5\u865a\u62df\u8d27\u5e01\u5c06\u88ab\u6dfb\u52a0\u5230\u60a8\u7684\u94b1\u5305\u4e2d\u3002\n <\/div>\n
\n Client <\/b>\u7c7b\u7684\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\u6240\u793a-\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
class <\/span>Client:
   def <\/span>__init__(self):
      random = Crypto.Random.new<\/span>().read
      self._private_key = RSA.generate<\/span>(1024, random)
      self._public_key = self._private_key.publickey<\/span>()
      self._signer = PKCS1_v1_5.new<\/span>(self._private_key)
   @property
   def <\/span>identity(self):
      return
binascii.hexlify<\/span>(self._public_key.exportKey<\/span>(format='DER'<\/span>)).decode<\/span>('ascii'<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u6d4b\u8bd5\u5ba2\u6237\u7aef<\/h3>\n
\n \u73b0\u5728\uff0c\u6211\u4eec\u5c06\u7f16\u5199\u4ee3\u7801\u6765\u8bf4\u660e\u5982\u4f55\u4f7f\u7528
\n Client <\/b>\u7c7b-\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
Dinesh = Client()
print <\/span>(Dinesh.identity)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u4e0a\u9762\u7684\u4ee3\u7801\u521b\u5efa
\n Client <\/b>\u7684\u5b9e\u4f8b\uff0c\u5e76\u5c06\u5176\u5206\u914d\u7ed9\u53d8\u91cf
\n Dinesh <\/b>\u3002\u6211\u4eec\u901a\u8fc7\u8c03\u7528
\n identity <\/b>\u65b9\u6cd5\u6765\u6253\u5370
\n Dinesh <\/b>\u7684\u516c\u94a5\u3002\u8f93\u51fa\u663e\u793a\u5728\u8fd9\u91cc-\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
30819f300d06092a864886f70d010101050003818d0030818902818100b547fafceeb131e07
0166a6b23fec473cce22c3f55c35ce535b31d4c74754fecd820aa94c1166643a49ea5f49f72
3181ff943eb3fdc5b2cb2db12d21c06c880ccf493e14dd3e93f3a9e175325790004954c34d3
c7bc2ccc9f0eb5332014937f9e49bca9b7856d351a553d9812367dc8f2ac734992a4e6a6ff6
6f347bd411d07f0203010001
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u7ee7\u7eed\u5728\u4e0b\u4e00\u7ae0\u4e2d\u521b\u5efa\u4ea4\u6613\u3002\n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[],"class_list":["post-2234","post","type-post","status-publish","format-standard","hentry","category-python_qkl"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2234"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=2234"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2234\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=2234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=2234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=2234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}