Different SHA1 Hash result between Java and C#

前端 未结 3 1555
心在旅途
心在旅途 2021-01-03 05:15

I\'ve a big problem. I using this C# function to encode my message:

byte[] buffer = Encoding.ASCII.GetBytes(file_or_text);
SHA1CryptoServiceProvider cryptoTr         


        
3条回答
  •  一生所求
    2021-01-03 05:52

    The change to use ISO-8859-1 on the C# side is easy:

    byte[] buffer = Encoding.GetEncoding(28591).GetBytes(file_or_text);
    

    However, both this and ASCII will lose data if your text contains Unicode characters above U+00FF.

    Ideally if your source data is genuinely text, you should use an encoding which will cope with anything (e.g. UTF-8) and if your source data is actually binary, you shouldn't be going through text encoding at all.

提交回复
热议问题