简体   繁体   中英

C# - String stored as Base64, but the retreived string is not a valid base64 string

I'm using Base64 encoding to store values from my data structure into a string. Basically what I do is convert a byte array into base64 string

string StoredData = Convert.ToBase64String(ByteArray); 

I then divide StoredData into strings of a maximum length of 256 Characters and store them as an ASCII string (in AutoCAD XData as an DxfCode.ExtendedDataAsciiString ) .

When I want to retrieve my data I do the following:

First I combine each 256 long string using StoredData = sting1 + string2 + ... Then I convert StoredData back into ByteArray using

var ByteArray = Convert.FromBase64String(StoredData);

Now this has worked great for me and my clients until a month ago, where one of my clients has had some crash and errors popping up. I asked him to send me his stored data, and I got surprised to see that his data contained invalid Base64 Characters (see sample below)

tM7x24QLLLALr5ivAx3XFAM7uciYXrCjKXSFd3XOL/KGIc3C+JMO8QjHT/4c+puYrNLq5r9Is0vpDKyuxw9I6R3f1LuOYSdHS6XgZJEyMvGwSHNRSYJ/a0IoumQftB3XspQRwp4QSd7qcUVsrXw0+2RS/sd2vAvUFxEQgwsHaabb01YjchGeyxr1f78A4qy2BL/oHAsRak9UYN0mDzhZgbhpahlgdK3eWd8b2BTM01lWh74pYUrJR+JfQ0tw0Eu㿔

Z/1JxBMUv2cB6NrFehSuNF9l4dhAaZQ+TcIClZmk/ZC8TJ0rKka/J+HqhLDAwWExB3nXoIi00uJnE7J4R6rU+Q==

as you can see the first 256 long string had an invalid Base64 character (㿔)

Why is that happening? can this be related to the users computer? I tried to replicate this error without any success and because I don't have access to their computers, I'm starting to think it might be something on their side.

The application uses .Net framework version 4.5.

Edit: it turned out client has sent me a recovered document which didn't recover the text strings properly which explains the corrupted string.

事实证明,应用程序已崩溃,客户端已使用损坏的字符串恢复了工程图文档。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM