No announcement yet.

AESSOCK - Decode on serversite

  • Filter
  • Time
  • Show
Clear All
new posts

  • AESSOCK - Decode on serversite

    Hello all,

    my question is, how i must decode the AES-Stream on serversite?

    In the docu i read, that the first 16 bytes are the IV-Bytes...I must cut this on serversite and copy the rest chunk of bytes to another bytearray? How must i do this.

    Need all help,


    greets Issahie

  • #2
    Hello again,

    now is my problem on serversite...(Used dotnet with c# with AESManaged)
    I get on serversite the IV-Vector and Encoded Bytes from Matchport.

    But when i try to decode, an error orcured:

    "Length of the data to decrypt is invalid error"

    What can i do? I'm desperate. Need help thanks.

    The code looking:

            /// <summary>
            /// AES 16byte decrypte methode with ChiperDataBytes and string Password.
            /// Return AES decrypted bytes as reference into OutData(null initialize).
            /// </summary>
            /// <param name="ChiperData"></param>
            /// <param name="OutText"></param>
            /// <param name="Password"></param>
            /// <returns>RUNNING_OK or DECRYPT_ERROR</returns>
            public int DecrypteAES(byte[] ChiperData, ref string OutData, byte[] Key, byte[] IV)
                    //Memorystream to get decrypted bytes
                    MemoryStream DecMS = new MemoryStream();
                    //Create Rijndael AES-Object
                    AesManaged rAES = new AesManaged();
                    rAES.KeySize = 128;
                    rAES.Key = Key;
                    rAES.IV = IV;
                    rAES.Mode = CipherMode.CFB;
                    //Create CryptoStream need to copy datas to memory
                    CryptoStream SecCS = new CryptoStream(DecMS, rAES.CreateDecryptor(), CryptoStreamMode.Write);
                    //Write decrypted bytes to memory
                    SecCS.Write(ChiperData, 0, ChiperData.Length);
                    //Copy in reference bytes
                    OutData = Encoding.ASCII.GetString(DecMS.ToArray());
                    return RUNNING_OK;
                { return DECRYPT_ERROR; }


    • #3
      I'm not sure what AES tools you are using but generally:
      The first packet contains the 16 byte IV. Then, any TCP stream data follows in one or more packets until the connection is torn down. Your decoder, will need to handle this fact. Typically you only set the IV once, and the CFB decoder with rotate the IV as needed. It looks to me that you are resetting the IV on each call, and "might" not even be passing any data to be deciphered. Please bare in mind - you are asking questions about the "host application" side - this is not our responsibility.


      • #4
        Which "padding" - mode is use for a TCP/128Bit/CFB connection?

        I can choose this modes:

        Name Beschreibung
        ANSIX923 The ANSIX923 padding string consists of a sequence of bytes filled with zeros before the length.
        ISO10126 The ISO10126 padding string consists of random data before the length.
        None No padding is done.
        PKCS7 The PKCS #7 padding string consists of a sequence of bytes, each of which is equal to the total number of padding bytes added.
        Zeros The padding string consists of bytes set to zero.

        I get ervery run the same error:

        "Length of the data to decrypt is invalid error"

        Whats mean this error?

        thanks for help


        • #5

          i have solved the problem.

          On serversite i have getted 76 bytes...but AES work to next 16bytes...
          On serversite the paddingmode has not work. I padded on serversite manually to 80bytes. After them i subtract 4bytes from decoded string.

          I wish for next SDK release, that on AESSOCK automatically the TCP-bytes padded to next aes block.

          PHP Code:
              ''' <summary>
          If receive bytes not an AES blocksizepadded bytes to next AES blocksize.
          ''' </summary>
          <param name="btCipher">Encoded datas</param>
          ''' <param name="AESBlock">16, 32, 64</param>
          ''' <remarks>Author: Issa Pourgholam Date: 14.04.2009</remarks>
          Public Function DecryptAESPadding(ByRef btCipher() As Byte, ByRef AESBlock As Int64) As Integer
          No padded needed if zero
          If btCipher.LongLength AESBlock 0 Then Return 0

          'Padded bytes to next AES BlockSize
                      Dim NextBlockSize As Int64 = Math.Round((btCipher.LongLength / AESBlock), 0, MidpointRounding.AwayFromZero)
                      NextBlockSize *= AESBlock

          Resize array
          ReDim Preserve btCipher(NextBlockSize 1)
          Catch ex As Exception
          Return -1
          End Function