Click here to Skip to main content
15,116,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have generated a random string, Encrypted it using DES algorithm.

now I am trying to decrypt it, but facing problem while converting encrypted string into memory stream.

What I have tried:

my code is as follows:
C#
public static MemoryStream Demo(string str)
       {
           MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(str));
           return memoryStream;
       }


Encrypted string is as below:

C++
rb3Cmy54Q8sANMHkelt9QzqOnM3enifu6v7AG5567oiqDk5ijwSwcSzfxUgHm4xD


Error which I am getting while converting encrypted string into memorystream in debugging mode is as below

C#
ReadTimeout = 'memoryStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'
WriteTimeout = 'memoryStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'


is there any problem with the method, or I'm doing it wrong way?
Posted
Updated 31-Jul-16 21:35pm

1 solution

Check your data: When I copy and paste your code and data:
C#
private void butTestIt_Click(object sender, EventArgs e)
    {
    string str = "rb3Cmy54Q8sANMHkelt9QzqOnM3enifu6v7AG5567oiqDk5ijwSwcSzfxUgHm4xD";
    MemoryStream ms = Demo(str);
    }

public static MemoryStream Demo(string str)
    {
    MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(str));
    return memoryStream;
    }
I get no error at all: the buffer is fine, and 48 bytes long.
   
Comments
Sachin Makwana 1-Aug-16 2:38am
   
string str = "xSlDJ5yNyfxUkx9ri8KvVwHNFtYGnkqreI5DTKCwKIo=";

please try above string. It is converting it into buffer but also throwing ReadTimeOut and WriteTimeOut exception. I am always getting CanTimeOut option value as false.

as per the discussion here

http://stackoverflow.com/questions/8487860/readtimeout-threw-an-exception-when-converting-byte-array-to-stream

I'm getting exception as value of CanTimeOut is always false.
OriginalGriff 1-Aug-16 2:55am
   
32 bytes, no problems.
And remember this is your code I copied and pasted.
So what am I doing that is different to you?
Sachin Makwana 1-Aug-16 3:58am
   
you are correct, 32 bytes, no problem. But why I'm getting ReadTimeOut and WriteTimeOut exception? This is causing me problem while I am applying decryption logic as per the following link.

http://www.codeproject.com/Articles/19538/Encrypt-Decrypt-String-using-DES-in-C

it gives me error "Bad Data". So, I thought that i might be doing it wrong way or it is causing because of the exception of "ReadTimeOut" and "WriteTimeOut" which i'm getting in debugging mode.
OriginalGriff 1-Aug-16 4:09am
   
Well, it's got to be something to do with your data - if the same code works here and not there, it's got to be that the string value we input isn't the same (although it may look like it).
So what happens when you feed it a constant string like I did? I'm guessing it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900