SteamKit2.CryptoHelper.AdlerHash C# (CSharp) Method

AdlerHash() public static method

Performs an Adler32 on the given input
public static AdlerHash ( byte input ) : byte[]
input byte
return byte[]
        public static byte[] AdlerHash( byte[] input )
        {
            uint a = 0, b = 0;
            for ( int i = 0 ; i < input.Length ; i++ )
            {
                a = ( a + input[ i ] ) % 65521;
                b = ( b + a ) % 65521;
            }
            return BitConverter.GetBytes( a | ( b << 16 ) );
        }

Usage Example

Ejemplo n.º 1
0
            /// <summary>
            /// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data.
            /// If the chunk has already been processed, this function does nothing.
            /// </summary>
            /// <param name="depotKey">The depot decryption key.</param>
            /// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception>
            public void Process(byte[] depotKey)
            {
                if (depotKey == null)
                {
                    throw new ArgumentNullException(nameof(depotKey));
                }

                if (IsProcessed)
                {
                    return;
                }

                byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey);

                if (processedData.Length > 1 && processedData[0] == 'V' && processedData[1] == 'Z')
                {
                    processedData = VZipUtil.Decompress(processedData);
                }
                else
                {
                    processedData = ZipUtil.Decompress(processedData);
                }

                byte[] dataCrc = CryptoHelper.AdlerHash(processedData);

                if (!dataCrc.SequenceEqual(ChunkInfo.Checksum))
                {
                    throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?");
                }

                Data        = processedData;
                IsProcessed = true;
            }
All Usage Examples Of SteamKit2.CryptoHelper::AdlerHash