473,382 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help with "Length of the data to decrypt is invalid" message error

SM
Hi,
I need your help, the following code is not working, ret = sr.ReadToEnd()
throws the message error : Length of the data to decrypt is invalid.
Any idea ?
thank you

public string Decrypting(string Source, string Key)
{
string ret = "";
try
{
// convert from Base64 to binary
byte[] bytIn =
System.Convert.FromBase64String(Source);

// create a MemoryStream with the input
System.IO.MemoryStream ms = new
System.IO.MemoryStream(bytIn, 0, bytIn.Length);

byte[] bytKey = GetLegalKey(Key);

// set the private key
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;

// create a Decryptor from the Provider Service
instance
ICryptoTransform encrypto =
mobjCryptoService.CreateDecryptor();

// create Crypto Stream that transforms a stream
using the decryption
CryptoStream cs = new CryptoStream(ms, encrypto,
CryptoStreamMode.Read);

// read out the result from the Crypto Stream
System.IO.StreamReader sr = new
System.IO.StreamReader(cs);

ret = sr.ReadToEnd();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
return ret;
}

Jun 27 '08 #1
1 2480
On Thu, 08 May 2008 06:41:24 -0700, SM <sa*******@hotmail.comwrote:
I need your help, the following code is not working, ret = sr.ReadToEnd()
throws the message error : Length of the data to decrypt is invalid.
Any idea ?
Unfortunately, the most obvious idea is that the length of the data to
decrypt is in fact invalid.

If you can post a concise-but-complete code example that reliably
demonstrates the problem from start to finish, then perhaps some advice
can be offered. Such a sample would start with some given data, would
encode the text to bytes, encrypt it, convert to Base64, and then pass
that result to something like you've posted here to be converted back from
Base64 and then decrypted and read as text.

Without such an example, it's hard to say. You've only posted half of the
implementation, and the error could be somewhere in the encryption stage,
or some asymmetry between a valid encryption and your decryption code.

Pete
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Morris | last post by:
I'm new to .NET and just trying a few things out, like emailing. I created a form in Visual Studio .Net to input some information for generating an email and I'm getting the following error when it...
1
by: arvee | last post by:
Hi - I'm updating an Oracle table with an empty string and getting the error: An unhandled exception of type 'System.Exception' occurred in system.data.dll Additional information: Parameter...
3
by: 21novembre | last post by:
Hi all, I made a question several days before to describe my strange trouble of mysqldump. But I still can't figour it out. Well, I just want to ask another question whether I could just backup...
3
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length...
7
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
2
by: Harrie Verveer | last post by:
Hi, I'm building quiet a large webapplication (CMS) in ASP.NET. On localhost the application runs fine. For publishing we use 2 hosting providers at the moment (let's call those 'A' and 'B')....
5
by: Dominiek | last post by:
Hi, I have a strange problem. during the developement of my program, while progressively writing more and more code, the callstack of my program gets deeper and deeper (7 levels). Then, all...
4
by: vunet.us | last post by:
Hi all, I am converting my app to AJAX-based. I have a form that submits some data including images. When I use AJAX XmlHttpRequest I am unable to submit the form with...
4
by: floppyzedolfin | last post by:
Hello! I'm actually encoding an encryption / decryption program. The encryption programes takes a file path in parameter, and encrypts the contents of the file and stores that into another file. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.