As I see it, you're converting the key bytes directly into ASCII text. If you do that, there might be some characters that will not show up and when you copy it elsewhere, it probably will not be there, and you'll lose a few characters, leading to the invalid keysize.
If you're planning on using StreamWriter.WriteLine()
, try using Convert.ToBase64String()
and Convert.FromBase64String()
to convert your key to/from Base64.
b64Key = Convert.Base64String(desCrypto.Key)
sw.WriteLine(b64Key)
sw.Close()