473,387 Members | 1,517 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,387 software developers and data experts.

Padding is invalid and cannot be removed.

This is driving me insane. Ive checked every sample and cant see anything happening differently. I'm sending the file over a network so the key and IV bytes are sent with the file to be used to decrypt, but every time it goes to decrypt i get "Padding is invalid and cannot be removed." Please give me at least a clue someone.

Edit : I know I posted this under the wrong language, my bad. Its c# not c

here's my code:
Expand|Select|Wrap|Line Numbers
  1.  public class SymetricEncryption
  2.     {
  3.         public static int decryptBytes(byte[] boggledData, byte[] key, byte[] IV, out byte[] DecryptedBytes)
  4.         {
  5.             RijndaelManaged symmetricKey = new RijndaelManaged();
  6.             symmetricKey.Mode = CipherMode.CBC;
  7.  
  8.  
  9.             ICryptoTransform decryptor = symmetricKey.CreateDecryptor(key, IV);
  10.             MemoryStream memoryStream = new MemoryStream(boggledData);
  11.             CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
  12.  
  13.             DecryptedBytes = new byte[boggledData.Length];
  14.             int read = cryptoStream.Read(DecryptedBytes, 0, boggledData.Length);
  15.  
  16.             memoryStream.Close();
  17.             cryptoStream.Close();
  18.             return read;
  19.         }
  20.         public static byte[] encryptBytes(byte[] Data, out byte[] key, out byte[] IV)
  21.         {
  22.  
  23.             RijndaelManaged symmetricKey = new RijndaelManaged();
  24.             symmetricKey.Mode = CipherMode.CBC;
  25.             symmetricKey.GenerateKey();
  26.             symmetricKey.GenerateIV();
  27.             key = symmetricKey.Key;
  28.             IV = symmetricKey.IV;
  29.  
  30.             ICryptoTransform encryptor = symmetricKey.CreateEncryptor(key, IV);
  31.             MemoryStream memoryStream = new MemoryStream();
  32.             CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
  33.             byte[] encryptedBytes = new byte[Data.Length];
  34.             cryptoStream.Write(Data, 0, Data.Length);
  35.  
  36.  
  37.             cryptoStream.FlushFinalBlock();
  38.             byte[] cipherBytes = memoryStream.ToArray();
  39.  
  40.             memoryStream.Close();
  41.             cryptoStream.Close();
  42.  
  43.             return cipherBytes;
  44.  
  45.         }
Jan 4 '10 #1
1 11488
I solved my prob. It was in the transport, I sent an integer as 3 bytes...and forgot to read my file into my buffer. duh
I shouldn't smoke as much weed while I code...
Jan 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nicholas Holder | last post by:
A client creates a connection to the server using the TCPListener/Client classes and transfers data via a NetworkStream. When the client connects, the server creates a process and redirects its...
0
by: Robert Smith | last post by:
I am getting the following error being caught in my application_error method... I have no code referencing the crypto classes. I have found nothing on the net outside of people with crypto...
0
by: mjweiner | last post by:
I have an ajax.asp.net application that is running very well, however, my error log is continuing to fill with "padding is invalid and cannot be removed" These errors report that the url with the...
4
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
I thought the following code worked for me until I looked closer. My first clue came when I tried to decrypt the file, and got a CryptographicException saying: Padding is invalid and cannot be...
2
by: Brent K | last post by:
Ok, I have an internal intranet website created in visual studio 2005, c#. It was running fine for months, and then all of the sudden a few days I started getting these errors emailed to me (I have...
1
by: rdlauer | last post by:
For some time now we've been seeing seemingly random errors thrown by an application "Padding is invalid and cannot be removed". Everything I've read about this online suggests that the machine key...
3
by: floppyzedolfin | last post by:
Hi there. I'm coding an encryption / decryption program. At this very moment, I think I should be pretty close from the end, but there's something blocking me on my way. There's a "Padding is...
0
by: Amelyan | last post by:
Why does this happen? How to fix it? Once in a while I get error in ~/ScriptResource.axd?d=... System.Reflection.TargetInvocationException: Exception has been thrown by the target of an...
4
by: MC | last post by:
Could someone please explain why I get 10-15 errors a day from my site after the "googleBot" has visited? Regards MC --------Error--------- Padding is invalid and cannot be removed....
9
by: AG | last post by:
I occassionally get the following exception from an ASP.NET 2.0 Web Application running on a shared web host. I have no way of knowing what the actual request page was as it never happens when I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.