首先,让我首先说明我不是一个密码学家,我也不擅长编写c代码,所以如果这个问题的答案显而易见或得到回答,请原谅.我正在开发一个消息传递程序,不能在目标平台上使用TLS.因此,我需要找到一种使用对称预共享密钥密码(如AES)加密每条消息的方法.
我正在寻找一种方法来加密和解密一端的mbedtls程序(例如aescrypt2)和另一端的nodejs程序之间的数据.Mbedtls,以前的polarssl,是一个为嵌入式设备提供加密的库.源代码中包含一些示例程序,如aescrypt2,rsaencrypt,ecdsa和crypt_and_hash.
当使用aescrypt2对生成的加密数据进行解密时,Aescrypt2工作正常,但我似乎无法使用aescrypt加密数据,使用nodejs加密或任何其他程序解密,包括openssl.例如:
echo 'this is a test message' >test.txt
aescrypt 0 test.txt test.out hex:E76B2413958B00E193
aescrypt 1 test.out test.denc hex:E76B2413958B00E193
cat test.denc
this is a test message
Run Code Online (Sandbox Code Playgroud)
使用openssl:
openssl enc -in out.test -out outfile.txt -d -aes256 -k E76B2413958B00E193
bad magic number
Run Code Online (Sandbox Code Playgroud)
一些当前不起作用的示例节点代码
var crypto = require('crypto');
var AESCrypt = {};
AESCrypt.decrypt = function(cryptkey, iv, encryptdata) {
encryptdata = new Buffer(encryptdata, 'base64').toString('binary');
var decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
decoded = decipher.update(encryptdata, 'binary', 'utf8');
decoded += decipher.final('utf8');
return decoded;
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我正在开发的使用 aiogram 的电报机器人中发送加密货币的价格警报。我遇到的问题是,我不确定如何启动一个函数作为后台、非阻塞线程,然后继续启动调度程序。我知道如何使用标准同步电报机器人来做到这一点,但我对我应该用 aiogram 做什么感到困惑。我读到我可以dp.loop.create_task 在这里使用,但这会引发错误Nonetype has no attribute create_task。这是我尝试执行这些线程的代码:
print('Starting watchlist process, this needs to run as a non blocking daemon...')
dp.loop.create_task(wl.start_process())
print('Starting broadcaster, this needs to run as a non blocking daemon ... ')
dp.loop.create_task(broadcaster())
print('Starting the bot ...')
executor.start_polling(dp, skip_updates=True)
Run Code Online (Sandbox Code Playgroud)
我只需要wl.start_process和broadcaster函数在后台运行。我该如何实现这个目标?
这是start_process:
async def start_process(self):
"""
Start the watchlist process.
:return:
"""
threading.Thread(target=self.do_schedule).start()
await self.loop_check_watchlist()
Run Code Online (Sandbox Code Playgroud)
这是broadcaster:
async def broadcaster():
count = 0
while True:
uid_alerts …Run Code Online (Sandbox Code Playgroud)