locked
Error in Decryption --> Invalid padding and Data size is not block size multiple RRS feed

  • Question

  • User-656433674 posted


    Hi All,

    Could you please help me on this error anybody its very urgnet issue in production.

    i have an issue while doing the decription with ingrainkey value got below 2 errors.
    1. Error in Decryption --> Invalid padding.
    2. Error in Decryption --> Data size is not block size multiple.
    why these two above errors got while doing decription with current key but same files encripted without
    any errors and we are not able to download the files form UI side and got above two errors those file manualy able to opened.
    Please help me what is the issue here from files or decription/encription/ code side while download the files.

    Thansks in advance.

    Regards,
    Narasimha

    Monday, November 3, 2014 7:09 AM

All replies

  • User-1151753377 posted

    Hi pulanarasima

    Welcome to the ASP.NET forum.

    i have an issue while doing the decription with ingrainkey value got below 2 errors.
    1. Error in Decryption --> Invalid padding.
    2. Error in Decryption --> Data size is not block size multiple.

    About these error messages, if you could provide some main code, maybe it is helpful for someone to analysis your problems and give you some suggestions.

    I find a similar thread and you could try to refer to it and hope it could helpful for you.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/d1788582-bf8c-43ec-a686-49647c359136/unexplained-cryptographicexception-padding-is-invalid?forum=netfxbcl

    Best Regards,

    Summer

    Tuesday, November 4, 2014 9:20 PM
  • User-656433674 posted

    Hi Summer,

       Thanks for giving response and please find below code...decryption.Please help me on this .

    FileStream fSource;
    FileStream fDestination;
    ICryptoTransform dec;
    Byte[] inputChar = null;
    Byte[] decryptedChar = null;
    //Int64 bfrSize = 9999999;
    int count;
    int decryptedCount;
    int dataSize = 150000;

    string sourcePath = ConfigurationSettings.AppSettings["EncryptedBackUpFilesPath"] + fileName;
    string destinationPath = ConfigurationSettings.AppSettings["DecryptedFiles"] + fileName;
    fSource = File.OpenRead(sourcePath);
    fDestination = File.Create(destinationPath);
    inputChar = new Byte[dataSize + 16];
    decryptedChar = new Byte[dataSize + 16];

    dec = nKey.CreateDecryptor();

    try
    {
    count = fSource.Read(inputChar, 0, dataSize);
    while (count > 0)
    {
    decryptedCount = dec.TransformBlock(inputChar, 0, count, decryptedChar, 0);
    fDestination.Write(decryptedChar, 0, decryptedCount);
    count = fSource.Read(inputChar, 0, dataSize);
    fDestination.Write(decryptedChar, 0, decryptedCount);
    AesManaged aes = new AesManaged();
    // aes.Padding = PaddingMode.None;
    }
    decryptedChar = dec.TransformFinalBlock(inputChar, 0, count); ---here getting the those two errors.

    fDestination.Write(decryptedChar, 0, decryptedChar.Length);
    Logger.LogError(destinationPath + " is decrypted. POMID is --> " + pomId);

    //CryptoStream crStream = new CryptoStream(fDestination, nKey.CreateEncryptor(), CryptoStreamMode.Write);
    //crStream.FlushFinalBlock();}

    catch (NAEException ex)
    {
    Logger.LogError("Error in Decryption --> " + ex.Message);
    }
    finally
    {
    inputChar = null;
    decryptedChar = null;
    fSource.Flush();
    fDestination.Flush();
    fDestination.Close();
    fSource.Close();
    }

    Tuesday, November 18, 2014 6:18 AM
  • User-1538479794 posted

    Hi

    please find below code...decryption.Please help me on this .

    These code couldn't work? or have some error messages? please provide more information about your requirement?

    May

    Friday, November 21, 2014 3:55 AM