RSA Exception {“Bad Length.\r\n”} Noi Matter What My Key Size Is

后端 未结 1 1710
日久生厌
日久生厌 2021-01-15 17:48

I am getting the runtime error {\"Bad Length.\\r\\n\"} on the line:

return rsa.Encrypt(bytes, true);

This is in the function:



        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 18:36

    This is the same error I found when I tried the code of one or your other post.

    Change this

    byte[] fileBytes = Encoding.Default.GetBytes(xmlDoc.OuterXml);

    to this

    byte[] fileBytes = Encoding.Default.GetBytes(xmlDoc.ToString());

    I would also suggest that you change your encoding from default to Encoding.ASCII or something more defined. It will be easier to convert it to a string to save and then back to a byte array to decrypt.

    0 讨论(0)
提交回复
热议问题