如何从frombase64string生成内存流? [英] How to generate memorystream from frombase64string?
问题描述
我已经生成了一个随机字符串,使用DES算法加密它。
现在我正在尝试解密它,但在将加密字符串转换为内存流时遇到问题。
我的尝试:
我的代码如下:
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:
public static MemoryStream Demo(string str)
{
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(str));
return memoryStream;
}
加密字符串如下:
Encrypted string is as below:
rb3Cmy54Q8sANMHkelt9QzqOnM3enifu6v7AG5567oiqDk5ijwSwcSzfxUgHm4xD
在调试模式下将加密字符串转换为内存流时出错的错误如下所示< br $> b $ b
Error which I am getting while converting encrypted string into memorystream in debugging mode is as below
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?
推荐答案
检查你的数据:什么时候我复制并粘贴您的代码和数据:
Check your data: When I copy and paste your code and data:
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;
}
我没有得到任何错误:缓冲区很好,长度为48个字节。
I get no error at all: the buffer is fine, and 48 bytes long.
这篇关于如何从frombase64string生成内存流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!