❔ Encoding Confusion and string variables
Hello! I am trying to encrypt a string, send it between two clients, and then decrypt the string. Which sounds simple enough but where I've hit a snag is in string encodings, or so I believe.
I am using the following code to encrypt and decrypt my string (userPassWord)
This works if I run it in isolation and just pass the result from one into the other. However! Where I am hitting a snag is that I cannot send the encrypted string as a byte[] but I need to send it as a string instead. However whenever I convert that byte array to a string and then back, it ends up either being an incorrect blocksize or decoding incorrectly. Do any of you know how to do this? Thanks a ton!
4 Replies
I solved this but I'll leave this here undeleted in case anyone else ever searches for something similar. Essentially the problem is that Encoding.GetString doesn't preserve the original bytes perfectly if they contain non-ascii characters. In my case they do. Convert.ToBase64String and Convert.FromBase64String do preserve the original bytes
i hope these aren't security critical passwords
because encryption is NEVER an option for passwords
They aren't. It's just something passed between two users to identify each other. Their actual account passwords are stored properly hashed and salted, but for reasons they need to be able to pass a string to eachother which is encrypted like this
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.