Re: Data decryption issue



Ok, I have the UTF8Encoding class in place, and it seems to be working fine.
Now I am trying to run the decrypt, and am getting an error that I can't
figure out. The Decrypt function is similar to the posted one, but with the
encoding changes. To use it, I'm running a SQL statement against the
function as "SELECT dbo.Decrypt(Name1) FROM Customers." Now I'm getting an
error as follows from MS SQL Server:

Msg 6522, Level 16, State 2, Line 1
A .NET Framework error occurred during execution of user defined routine or
aggregate 'Decrypt':
System.Security.Cryptography.CryptographicException: Padding is invalid and
cannot be removed.
System.Security.Cryptography.CryptographicException:
at
System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer,
Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
at
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
at System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at SQLEncryption.Encryption.Decrypt(Char[] InputString)
..

So, I have extra padding in place, but I don't know if the padding mode
matters. I've tried using PKCS7, ISO10126, and no padding modes. On the
PKCS7 and ISO10126, I can encrypt just fine, but the decrypt function
returns the above error, but the encrypt does not work when padding is
specified to be none.

"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.ufdeqrhw8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Mon, 04 Aug 2008 09:15:45 -0700, Tom Andrecht
<tom.andrecht@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Peter,

I do appreciate the advice. I did try the Convert routines again, and am
still running into trouble. Specifically, I have tried the
Convert.FromBase64CharArray and Convert.ToBase64CharArray functions

I recommended the Encoding class, not the Convert class.


.



Relevant Pages

  • Re: Padding is invalid and cannot be removed
    ... as base64 strings are built from 3-byte input, and the encoded data length must be a multiple of 4 padding must be used in some cases. ... the error you are receiving means the length of the base64 string is not correct, that is, somehow the browser is truncating the string. ... I assume it is trying to decrypt the ViewState ... inputBuffer, Int32 inputOffset, Int32 inputCount, Byte& ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Padding and block ciphers
    ... while giving to each padding byte the value of the padding length ... decrypt with the wrong key, if the padding that you had to apply to the ... lets say that the block cyper encrypts bytes. ... key produces a random mapping. ...
    (sci.crypt)
  • Re: Exception - Padding is Invalid
    ... Email: discussATadhdataDOTcom ... due to base64's algrothrym a the string length ... Padding is invalid and cannot be removed. ... inputBuffer, Int32 inputOffset, Int32 inputCount, Byte& outputBuffer, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Padding and block ciphers
    ... is padding and what isn't (consider what might happen if the padding ... and you only had to decrypt the last block to ... Yes but the attacker does not know if there even is any padding to begin ... So an incorrect key could in theory create what looks like padding ...
    (sci.crypt)
  • Re: Padding and block ciphers
    ... the key incorrect because the padding is incorrect. ... How would an attacker know if the padding is incorrect? ... and you only had to decrypt the last block to ...
    (sci.crypt)