通过之前的文章,我们已经知晓了Memo的大致工作原理,那就是: >发送者利用发送方的私钥和接收方的公钥生成共享密码,而接收者用接收方的私钥和发送方的公钥同样可以获取共享密码。  (图源 :[pixabay](https://pixabay.com/)) 当然了,共享密码生成还是需要经过一系列的处理,并且发送/接收方要按相同的流程和规范生成,这样才能正确地加密/解密。 那么问题来来了,明文有了,密码有了,我们用什么手段加密明文呢? 因为发送方和接收方用相同的密码加解密,所以要用对称加密算法,所谓对称加密,百度百科上这么介绍的: >采用单钥密码系统的加密方法,同一个密钥可以同时用作信息的加密和解密,这种加密方法称为对称加密,也称为单密钥加密。 而HIVE/STEEM的memo加密使用的是对称加密中最为常见的一种算法:AES (Advanced Encryption Standard)即***高级加密标准***,听听这名字,就不同凡响,哈哈。 # 安装pycrypto库 Python中使用AES的一种方法是使用`pycrypto`库,然后使用如下语句引入AES >`from Crypto.Cipher import AES` 然而因为我用的是一台新机器,所以出现了如下错误提示: >ModuleNotFoundError: No module named 'Crypto' 使用如下指令尝试安装`pycrypto` >`pip install pycrypto` 结果又出现如下错误: >configure: error: in `/tmp/pip-install-7_25hg67/pycrypto': >configure: error: no acceptable C compiler found in $PATH 缺啥装啥: >`sudo apt install gcc` 又出错: >src/MD2.c:31:10: fatal error: Python.h: No such file or directory >#include "Python.h" 还是缺啥装啥: >`sudo apt install python3-dev` 尽管看起来敲个指令很容易,可是家里的网速,网速真的伤不起 > 总算下载完了,再次执行: >`pip install pycrypto` 安装成功,耶: > # AES的使用 接下来是如何使用AES加密的问题,我把我珍藏多年的《密码编码学与网络安全——原理与实践》找了出来,然后发现根本看不懂。 steem-python中的初始化AES的核心代码如下: > 但是`AES.MODE_CBC`、`iv`都是些什么鬼?查了半天,终于找到了: * CBC(Cipher Block Chaining,加密块链)模式 * IV: 初始化向量 网上找了一段[示例代码](https://www.quickprogrammingtips.com/python/aes-256-encryption-and-decryption-in-python.html): 一般都是加密时用到iv,但是把iv以明文编码的形式打包到结果中,然后解密时先取出iv再参与计算: > 而HIVE/STEEM的memo加密则比较先进,iv和key都是由shared_secret、nonce计算得出,同样可以在接收端计算得出,无需明文传递。 所以看起来,还是HIVE/STEEM中对Memo加密处理的方法更先进一些呢。 好了,虽然更深入的理论我是研究不明白了,但是基本应该可以上手做了,撸起袖子加油干! # 相关链接 * [高级加密标准](https://baike.baidu.com/item/%E9%AB%98%E7%BA%A7%E5%8A%A0%E5%AF%86%E6%A0%87%E5%87%86/468774) * [AES 256 Encryption and Decryption in Python](https://www.quickprogrammingtips.com/python/aes-256-encryption-and-decryption-in-python.html)
author | oflyhigh |
---|---|
permlink | memo-and-aes |
category | hive-105017 |
json_metadata | {"tags":["cn","cutehive","cn-programming","memo","aes","include"],"image":["https://cdn.pixabay.com/photo/2016/12/08/08/28/virus-1891191_960_720.jpg","https://images.hive.blog/DQmTwK7CscaFUHCHpJgjvpNdEpXBgHoWAEG3cPdoyy3tecg/image.png","https://images.hive.blog/DQmNmcjFwQ9FRCz14EoofBxaXtxUgJ3aEYcUbcfnT6PBiGe/image.png","https://images.hive.blog/DQmZukMKtKgUjDPPaSbadd3BSgcymRRe61zyrcFik9CsPLg/image.png","https://images.hive.blog/DQmf6xrWk9hBhcDXaKPQuL6fEmrrSh6XzgzKD6aRqGtixpX/image.png"],"links":["https://pixabay.com/","https://www.quickprogrammingtips.com/python/aes-256-encryption-and-decryption-in-python.html","https://baike.baidu.com/item/%E9%AB%98%E7%BA%A7%E5%8A%A0%E5%AF%86%E6%A0%87%E5%87%86/468774"],"app":"hiveblog/0.1","format":"markdown"} |
created | 2020-05-06 03:50:00 |
last_update | 2020-05-06 03:50:00 |
depth | 0 |
children | 0 |
last_payout | 2020-05-13 03:50:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 32.624 HBD |
curator_payout_value | 29.146 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,254 |
author_reputation | 6,419,372,157,339,361 |
root_title | "每天进步一点点:Memo中的加密手段 & AES加密" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,212,485 |
net_rshares | 99,269,312,394,002 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
abit | 0 | 26,302,805,779,363 | 100% | ||
adm | 0 | 28,312,524,435,261 | 100% | ||
onealfa | 0 | 108,016,573,898 | 5% | ||
mangou007 | 0 | 11,141,420,623 | 7.25% | ||
gerber | 0 | 234,827,928,311 | 3.4% | ||
daan | 0 | 77,272,029,090 | 8% | ||
ezzy | 0 | 3,829,294,454,481 | 50% | ||
fundurian | 0 | 140,139,361,102 | 95% | ||
deanliu | 0 | 1,905,209,801,932 | 100% | ||
exyle | 0 | 1,118,892,053,907 | 12% | ||
joythewanderer | 0 | 384,573,480,086 | 50% | ||
lemooljiang | 0 | 508,713,050,910 | 88% | ||
ace108 | 0 | 545,847,090,226 | 25% | ||
laoyao | 0 | 46,903,801,273 | 100% | ||
somebody | 0 | 11,913,595,303 | 100% | ||
skysunny | 0 | 114,398,444 | 88% | ||
midnightoil | 0 | 164,583,114,393 | 100% | ||
xiaohui | 0 | 931,284,042,026 | 100% | ||
oflyhigh | 0 | 4,632,461,655,361 | 100% | ||
yulan | 0 | 16,734,987,097 | 100% | ||
bert0 | 0 | 31,955,315,309 | 7.25% | ||
rivalhw | 0 | 1,918,299,979,317 | 100% | ||
nextgen622 | 0 | 1,605,959,252,742 | 100% | ||
helene | 0 | 1,225,157,371,875 | 100% | ||
ffcrossculture | 0 | 395,167,232,974 | 100% | ||
themanualbot | 0 | 50,665,297,800 | 10% | ||
ethansteem | 0 | 395,484,156,334 | 100% | ||
sweetsssj | 0 | 14,257,384,448,602 | 35% | ||
netaterra | 0 | 343,476,546,302 | 16% | ||
someguy123 | 0 | 30,284,065,167 | 3.4% | ||
funnyman | 0 | 4,114,433,807 | 20% | ||
lexikon082 | 0 | 1,115,452,274 | 100% | ||
dapeng | 0 | 33,246,019,826 | 100% | ||
devilwsy | 0 | 3,384,963,082 | 100% | ||
janiceting | 0 | 3,398,957,169 | 100% | ||
timool | 0 | 917,006,979 | 88% | ||
lucknie | 0 | 16,002,137,544 | 88% | ||
dumping | 0 | 1,680,066,811 | 88% | ||
blackbunny | 0 | 73,618,411,494 | 100% | ||
elizacheng | 0 | 16,147,425,718 | 9% | ||
bxt | 0 | 242,558,104,268 | 100% | ||
lingfei | 0 | 82,548,314,021 | 100% | ||
justinashby | 0 | 43,107,266,051 | 100% | ||
yyyy | 0 | 463,586,821 | 100% | ||
teachblogger | 0 | 2,100,719,831 | 50% | ||
htliao | 0 | 38,333,923,149 | 20% | ||
dune69 | 0 | 12,065,378,637 | 8.4% | ||
curly-q | 0 | 2,209,669,121 | 100% | ||
mys | 0 | 746,106,645 | 0.23% | ||
exec | 0 | 247,363,085,591 | 100% | ||
eval | 0 | 858,028,916 | 100% | ||
sam99 | 0 | 4,207,367,850 | 100% | ||
ew-and-patterns | 0 | 205,346,416,268 | 10% | ||
d-pend | 0 | 49,624,930,418 | 1.7% | ||
susanli3769 | 0 | 152,995,007,622 | 100% | ||
violetmed | 0 | 5,026,816,204 | 0.85% | ||
otom | 0 | 15,785,470,010 | 20% | ||
travelgirl | 0 | 142,820,461,366 | 40% | ||
shitsignals | 0 | 2,289,200,239 | 1.7% | ||
catwomanteresa | 0 | 124,399,227,833 | 50% | ||
oldman28 | 0 | 33,277,879,904 | 48% | ||
liangfengyouren | 0 | 3,278,398,364 | 50% | ||
stevenmosoes | 0 | 2,720,604,363 | 50% | ||
igrinov | 0 | 4,884,910,515 | 10% | ||
cn-reader | 0 | 12,920,293,646 | 50% | ||
tvb | 0 | 21,117,510,746 | 30% | ||
skenan | 0 | 10,595,310,574 | 50% | ||
kimzwarch | 0 | 7,468,905,114 | 4% | ||
bboyady | 0 | 594,729,669 | 2% | ||
accelerator | 0 | 64,080,739,288 | 6.8% | ||
chinchilla | 0 | 236,388,116,514 | 100% | ||
chenlocus | 0 | 8,626,358,736 | 100% | ||
davidke20 | 0 | 10,019,677,852 | 4% | ||
roleerob | 0 | 2,742,012,419 | 0.61% | ||
xiaoshancun | 0 | 4,559,437,025 | 100% | ||
victory622 | 0 | 139,235,539,109 | 80% | ||
tatjanastan | 0 | 491,281,486,147 | 100% | ||
metten | 0 | 8,823,726,521 | 88% | ||
flamingirl | 0 | 1,807,637,361 | 7.25% | ||
pataty69 | 0 | 1,133,138,640 | 1.7% | ||
jychbetter | 0 | 3,215,756,917 | 100% | ||
caladan | 0 | 16,951,873,748 | 10.2% | ||
mrsyria | 0 | 41,144,211 | 100% | ||
blockbrothers | 0 | 13,596,152,308 | 6% | ||
cn-book | 0 | 985,320,156 | 88% | ||
emrebeyler | 0 | 58,720,516,504 | 3.4% | ||
cn-movie | 0 | 98,723,100 | 88% | ||
etherpunk | 0 | 1,391,714,954 | 25% | ||
itchyfeetdonica | 0 | 123,726,965,309 | 50% | ||
vivia | 0 | 2,828,047,571 | 88% | ||
girolamomarotta | 0 | 31,081,023,179 | 50% | ||
nealmcspadden | 0 | 51,349,828,156 | 3.4% | ||
maiyude | 0 | 1,326,844,914 | 50% | ||
suhunter | 0 | 957,081,637 | 50% | ||
ahmedsy | 0 | 1,068,065,300 | 100% | ||
xiaoli | 0 | 262,276,239 | 88% | ||
cadawg | 0 | 6,593,501,360 | 2.37% | ||
yjcps | 0 | 3,648,723,128 | 100% | ||
sudefteri | 0 | 14,996,441,033 | 100% | ||
happy-soul | 0 | 72,472,790,179 | 10% | ||
ethanlee | 0 | 5,669,045,714 | 100% | ||
retinox | 0 | 4,005,218,868 | 2.49% | ||
fishbb | 0 | 766,768,392 | 25% | ||
fredo77200 | 0 | 3,665,154,696 | 100% | ||
josevas217 | 0 | 3,319,247,667 | 5.07% | ||
bestboom | 0 | 27,922,816,283 | 3.4% | ||
freddio | 0 | 49,044,472,245 | 15% | ||
therising | 0 | 2,952,915,516,689 | 20% | ||
angelinafx | 0 | 4,814,601,730 | 6% | ||
tresor | 0 | 20,176,063,695 | 7.25% | ||
thebot | 0 | 160,857,869,257 | 100% | ||
crypto.piotr | 0 | 19,095,366,637 | 5% | ||
competeapp | 0 | 929,700,543,923 | 100% | ||
hmayak | 0 | 23,238,726,722 | 100% | ||
archisteem | 0 | 2,540,913,560 | 7.5% | ||
kahvesizlik | 0 | 1,216,895,761 | 100% | ||
moneybaby | 0 | 895,965,709 | 2.5% | ||
suonghuynh | 0 | 836,706,338,861 | 6% | ||
abcallen | 0 | 15,457,697,039 | 80% | ||
gallerani | 0 | 4,014,621,414 | 3.4% | ||
rachman-jr25 | 0 | 678,252,125 | 100% | ||
yestermorrow | 0 | 8,588,954,000 | 31% | ||
dalz | 0 | 21,783,716,877 | 10% | ||
smartvote | 0 | 361,757,546,732 | 6% | ||
blues-wclouds | 0 | 1,752,244,175 | 100% | ||
julian2013 | 0 | 11,555,996,192 | 5% | ||
dlike | 0 | 39,753,867,026 | 3.4% | ||
triptolemus | 0 | 4,590,325,928 | 3.4% | ||
voxmortis | 0 | 57,523,359,148 | 20% | ||
bobby.madagascar | 0 | 1,196,156,957 | 0.85% | ||
jamzmie | 0 | 1,275,717,653 | 15% | ||
merlin7 | 0 | 10,230,607,800 | 3.4% | ||
sasaadrian | 0 | 1,997,143,117 | 20% | ||
reverseacid | 0 | 771,155,892 | 5% | ||
memeteca | 0 | 1,221,766,781 | 7.25% | ||
cwow2 | 0 | 14,821,834,299 | 5% | ||
followjohngalt | 0 | 20,557,814,639 | 9.6% | ||
starrouge | 0 | 1,043,411,996 | 50% | ||
rasalom | 0 | 15,210,662,198 | 100% | ||
zerofive | 0 | 861,846,615 | 50% | ||
samsemilia7 | 0 | 7,720,524,510 | 40% | ||
bluesniper | 0 | 146,624,579,562 | 25% | ||
tagalong | 0 | 2,887,632,089 | 100% | ||
determine | 0 | 4,009,594,942 | 3.4% | ||
cnstm | 0 | 432,900,019,141 | 100% | ||
permaculturedude | 0 | 622,565,890 | 1.7% | ||
likuang007 | 0 | 37,061,973,864 | 100% | ||
lianjingmedia | 0 | 1,004,005,509 | 100% | ||
goodcontentbot | 0 | 798,999,566 | 15% | ||
chocolatelover | 0 | 4,000,334,788 | 40% | ||
mia-cc | 0 | 12,880,373,575 | 100% | ||
hungryharish | 0 | 5,704,540,695 | 100% | ||
elektroyazilim | 0 | 631,605,230 | 60% | ||
kryptogames | 0 | 88,654,956,445 | 20% | ||
lovelemon | 0 | 44,308,626,005 | 100% | ||
rj-photo | 0 | 1,375,610,929 | 100% | ||
vxc | 0 | 502,057,064 | 5.09% | ||
worldhelper | 0 | 1,460,144,031 | 5% | ||
triplea.bot | 0 | 3,622,374,002 | 12% | ||
steem.leo | 0 | 35,362,729,711 | 3.36% | ||
leo.voter | 0 | 8,107,456,722 | 0.51% | ||
hyborian-strain | 0 | 1,716,840,075 | 30% | ||
freddio.sport | 0 | 5,506,256,583 | 15% | ||
asteroids | 0 | 8,293,490,971 | 3.4% | ||
marlians.spt | 0 | 536,185,488 | 40% | ||
leo.syndication | 0 | 774,136,728 | 3.4% | ||
one.life | 0 | 3,114,748,185 | 3.39% | ||
maxuvd | 0 | 12,857,584,718 | 3.4% | ||
teresa.yaiyai | 0 | 8,142,979,703 | 100% | ||
downvoteme | 0 | -29,756,724,224 | -50% | ||
freedomteam2019 | 0 | 2,854,058,138 | 25% | ||
therealyme | 0 | 907,500,623 | 16% | ||
abdulwajid1978 | 0 | 720,595,822 | 100% | ||
gerbo | 0 | 0 | 3.4% | ||
starnote | 0 | 187,229,270 | 88% | ||
simply2koool | 0 | 10,504,718,280 | 25% | ||
ribary | 0 | 143,486,548,713 | 6% | ||
moochain.net | 0 | 188,747,879 | 88% | ||
bettyliu | 0 | 0 | 88% | ||
younggle | 0 | 0 | 88% | ||
steem-zh | 0 | 0 | 88% | ||
earthworld | 0 | 2,498,071,631 | 35% | ||
theisacoin | 0 | 44,605,606,650 | 1% | ||
steemcityrewards | 0 | 10,780,613,166 | 3.4% | ||
dpend.active | 0 | 650,055,937 | 0.42% | ||
lovequeen | 0 | 12,428,187,262 | 100% | ||
steemzh | 0 | 0 | 88% | ||
bnk | 0 | 8,448,155,638 | 7.25% |