Rijndael Length Of The Data To Decrypt Is Invalid
And Decrypt method: static string DecryptStringFromBytes(byte[] cipherText, byte[] Key) { using (RijndaelManaged rijAlg = new RijndaelManaged()) { rijAlg.Key = Key; rijAlg.Mode = CipherMode.ECB; rijAlg.Padding = PaddingMode.None; // Create a decrytor to perform the stream transform. Ok when I encrypt it is 20 when I decrypt is 32 How do I fixed this. The size of the encryped data should be the size of the input to the nearst block size.
OK, so having to be accepted and have an encrypted string out which is 44 char long, I now am unable to decrypt (aarrgghh): Length of the data to decrypt is invalid. Having looked around and read various posts it looks as though the conversion to a Base64String may be the problem but I can't see where it is wrong - many of the solutions I have seen appear to be identical to what I have.
Length Of The Data To Decrypt Is Invalid
Again, I'd really appreciate any help - extracts below: Encryption/Decryption Function Private byteKey As Byte = Encoding.UTF8.GetBytes('B499F4BF8D1E4C8BB26A2E') Private byteIV As Byte = Encoding.UTF8.GetBytes(',%u'm&'CXSy/T7x;4') Private Function Rijndael(ByVal sInput As String, ByVal bEncrypt As Boolean) As String ' Create an instance of encyrption algorithm. Dim rijndael As New RijndaelManaged ' Create an encryptor using key and IV - already available in byte as byteKey and byteIV Dim transform As ICryptoTransform If bEncrypt Then transform = rijndael.CreateEncryptor(byteKey, byteIV) Else transform = rijndael.CreateDecryptor(byteKey, byteIV) End If ' Create streams for input and output Dim msOutput As New System.IO.MemoryStream Dim msInput As New CryptoStream(msOutput, transform, CryptoStreamMode.Write) ' Feed data into the crypto stream. MsInput.Write(Encoding.UTF8.GetBytes(sInput), 0, Encoding.UTF8.GetBytes(sInput).Length) ' Flush crypto stream.
See More On Stackoverflow
If you're going to convert it to base64 you're going to have to decode it using Base64. At the moment you're taking the output Base64 byte array then using UTF8 to convert it back to bytes, which gives you a completely different value. You should be using instead of UTF8 for changing the string to bytes when decoding, then using UTF8 instead of Base64 for interpreting the data. EG: On the decode you'd want msInput.Write(Convert.FromBase64String(sInput), 0, Convert.FromBase64String(sInput).Length) And for the return when decoding: Return Encoding.UTF8.GetString(byteOutput).
When answering a question please:. Read the question carefully. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it.

Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.