473,624 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(stri ng Source, string Key)
{
string ret = "";
try
{
// convert from Base64 to binary
byte[] bytIn =
System.Convert. FromBase64Strin g(Source);

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

byte[] bytKey = GetLegalKey(Key );

// set the private key
mobjCryptoServi ce.Key = bytKey;
mobjCryptoServi ce.IV = bytKey;

// create a Decryptor from the Provider Service
instance
ICryptoTransfor m encrypto =
mobjCryptoServi ce.CreateDecryp tor();

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

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

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

Jun 27 '08 #1
1 2495
On Thu, 08 May 2008 06:41:24 -0700, SM <sa*******@hotm ail.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
4602
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 executes both on my server or on the server of the .NET service provider. I'm obviously missing something very basic and I'm hoping one of you can point out my error. Thank you for your assistance. Brian
1
14938
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 'p1': No size set for variable length data type: String. The column is nullable and of type varchar2(50). I'm aware that I can store DBNull.Value instead and Oracle won't complain, but, I was hoping to avoid
3
4688
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 my databases by copying the data folder to some place? Then if I meet some disaster, could I just copy the backup folder back to recover my databases? Thank you. Zh.y
3
29229
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 of the data to decrypt is invalid" and occurs on the csDecrypt.FlushFinalBlock.
7
17872
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 able to encrypt and then decrypt data okay as in the following code: // encrypt the data // Encryptor enc = new Encryptor(EncryptionAlgorithm.TripleDes); byte key = Encoding.ASCII.GetBytes("0123456789012345");
2
3505
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'). Hosting provider A doesn't give any problems and the application runs just fine. On hosting provider B there are some problems, and I just can't figure it out =(. My users login using FormsAuthentication. After clicking through the application...
5
3881
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 of a sudden, when calling a Sub with 2 parameters, a Hashtable(19 items) and a ArrayList(9 items), the value of these variables is gone, the debugger reports the value as {length=error: cannot obtain value}.
4
32517
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 ENCTYPE="multipart/form-data" (error 500). Without ENCTYPE="multipart/form-data", everything goes well. I think there is a header I must use in addition, but I cannot seem to find a good solution. Can you suggest? Thank you. Here is a part of xmlhttp request where I set...
4
6217
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. I'm using AES for it is quick, and RSA to encrypt AES, to transmit AES keys (it'll run on two separate computers). Please notice that - this is my first C# code :)
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.