【发布时间】:2019-07-16 20:52:58
【问题描述】:
使用 AES 库,我正在尝试将加密数据从 arduino 端发送到 raspberry pi 端。在 arduino 串行监视器上打印的加密数据与在 raspberry 端打印的数据不同。 可能是解码问题。
此外,在树莓派端解密时,它会给出一个错误,说“输入文本的长度必须是 16 的倍数”,当我用零填充输入(温度数据)时,它仍然给出相同的错误消息。
我尝试使用“utf-8”和“iso-8859-1”进行解码,但它仍然没有显示相同的解密数据。
Python 代码:
from Crypto.Cipher import AES
ser=serial.Serial(' /dev/ttyS0',9600)
st=ser.readline()
st1=st.decode('utf-8')
obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
ciphertext = obj.encrypt(message)
obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
obj2.decrypt(ciphertext)
ARDUINO 代码:
void aesTest (int bits)
{
aes.iv_inc();
byte iv [N_BLOCK] ;
int plainPaddedLength = sizeof(chartemp) + (N_BLOCK - ((sizeof(chartemp)-1) % 16));
byte cipher [plainPaddedLength];
byte check [plainPaddedLength];
aes.set_IV(myIv);
aes.get_IV(iv);
aes.do_aes_encrypt(chartemp,sizeof(chartemp),cipher,key,bits,iv);
aes.set_IV(myIv);
aes.get_IV(iv);
aes.printArray(cipher,(bool)false); //print cipher with padding
String cipher1=String((char*)cipher);
myserial.println(cipher1);
}
HERE charttemp 是从 LM35 IC 转换为字符数组的温度。
我希望树莓派端的输出能够正确解密
【问题讨论】:
-
我也尝试过使用base64,它没有显示预期的结果。请帮忙
标签: utf-8 aes raspberry-pi3