2

I have been trying to implement XTEA encryption on Cortex M3 Microcontroller in C , in IAR IDE , so far Encryption Decryption is working , but i am facing a problem , I have To Encode Ascii Strings,but the Encrypted String Sometimes contains a 0x00 in String Array ,not in end as null terminator but in middle somewhere , so the String functions do not get the correct length of String because of this extra 0x00 they assume its Null Terminator , Problem is that I have to Transmit this String over GPRS , and the backend is also using same kind of ASCII string expecting 0x00 only at the end , in firmware also rest of String Transmission is assuming it to be Null Terminating , is there any way to Replace this 0x00 in Encrypted String with some other value , in a manner that it can also be reproduced easily later in backend , suppose i add 0x01 to each Encrypted String Array , this may make one 0xff to 0x00 , is there a way to remove this 0x00 ,

or any other Simple Encryption Algorithm for Ascii String , easily implementable on microcontroller, that guarantee Non Zero value in encrypted string , the backend guys insist on having some algorithm being used in systems , does AES algorithm insures Non zero value?

4

3 回答 3

1

与其发明新的编码方案,不如考虑使用现有的编码方案。(您的文档会更容易。)

如果您的数据是ASCII,那么您只能使用 0 到 0x7F 的代码。 Base64是最好的方法。

于 2013-08-21T22:27:31.233 回答
0

如果你不介意你的字符串增长一点,你可以在编码期间用 0x01 0x01 替换 0x00 字节,用 0x01 0x02 替换 0x01 字节。

在远端,您可以在解码期间将 0x01 0x01 替换为 0x00 并将 0x01 0x02 替换为 0x01。

例如:

0x04 0x00 0x05 0x01 在传输过程中会变成 0x04 0x01 0x01 0x05 0x01 0x02。

于 2013-08-21T21:35:46.857 回答
0

您始终可以使用 base64 或其他编码方法,但我认为按照建议转义0x00 更好。

于 2013-08-21T22:07:19.397 回答