Decrypting in Python an string encrypted using .NET

后端 未结 2 1677
孤独总比滥情好
孤独总比滥情好 2021-02-04 13:46

I am trying to encrypt a string using C# and decrypt it using Python. The encryption/decryption part works as expected (i.e. I am able to decrypt the string I originally encrypt

2条回答
  •  无人共我
    2021-02-04 14:18

    The string is encoded to bytes using the UTF-16 encoding. The first two bytes are a BOM. Then each character is encoded to two bytes.

    From the documentation for Encoding.Unicode:

    Gets an encoding for the UTF-16 format using the little endian byte order.

    To get the original string you need to decode it back from UTF-16 bytes to a Unicode string.

    print aes.decrypt(text).decode('utf-16')
    

提交回复
热议问题