![]() Return (base64.b64encode(textoUnicodeToUtf8Literal(("".join())).encode('ISO-8859-1'))).decode()ĭef textoUnicodeToUtf8Literal(encodando): # Do the oposite of Convert.FromBase64String() from C# Return np.frombuffer(base64.b64decode(encrypted.encode()), np.uint8) # Do the same as Convert.FromBase64String() from C# Return = 'bg0uiF9CXIRt2TpwKwiRKuliKIul5DQJWa SZ Pu6b5Or/Lgyor4Z3Jix/xQVj2u' I had some time to develop this Solution for Python3.7, considering as example: ''' Argument = Most file-related classes use UTF8 by default and return Unicode strings. C# and Windows in general uses Unicode (UTF16 specifically), which is why I could post those characters in the answer. To avoid conversion errors you should use UTF8 on Python and C#. The only thing you can be certain about is that some codepages will fail and return ?, or the well defined Unicode Replacement Character � String s = Encoding.GetEncoding(1252).GetString(bytes) If you use : byte bytes = Convert.FromBase64String("UORSfV0=") One codepage that can decode this character is 1253, ie Latin1. ![]() Without knowing the actual codepage one can only guess. You need to know the correct codepage to use to decode it. The character is definitely outside the valid range. This is neither an ASCII nor a UTF8 string. Encoding.ASCII is the 7-bit character set while the Python string contains \xe4, ie ä. The Base64 string you used on the C# side has an extra space.Įven after that's fixed, the codepage is definitely wrong. There are multiple problems with this code. The rest is only meant to explain where ? came from and why. That string looks way too short for AES though. Without the code that attempts to decrypt the bytes buffer it's impossible to say what's wrong. There's no reason to look for bugs that weren't noticed by any. The OP attempted to convert the buffer to a string in order to compare the values. I suspect there's a problem with the decryption code which wasn't posted. How the byte buffer looks using various codepages has nothing to do with whether the byte values are correct. Besides, that string is way too short for AES. There's no reason to convert the buffer to a string before decrypting. ![]() ![]() AES deals with byte buffers, not strings.
0 Comments
Leave a Reply. |