SteamKit2.CryptoHelper.CRCHash C# (CSharp) Method

CRCHash() public static method

Performs CRC32 on an input byte array using the CrcStandard.Crc32Bit parameters
public static CRCHash ( byte input ) : byte[]
input byte
return byte[]
        public static byte[] CRCHash( byte[] input )
        {
            using ( Crc crc = new Crc( CrcParameters.GetParameters( CrcStandard.Crc32Bit ) ) )
            {
                byte[] hash = crc.ComputeHash( input );
                Array.Reverse( hash );

                return hash;
            }
        }

Usage Example

Ejemplo n.º 1
0
        public static byte[] Compress(byte[] buffer)
        {
            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    byte[] crc = CryptoHelper.CRCHash(buffer);

                    writer.Write(VZipHeader);
                    writer.Write((byte)Version);
                    writer.Write(crc);

                    Int32 dictionary     = 1 << 23;
                    Int32 posStateBits   = 2;
                    Int32 litContextBits = 3;
                    Int32 litPosBits     = 0;
                    Int32 algorithm      = 2;
                    Int32 numFastBytes   = 128;

                    SevenZip.CoderPropID[] propIDs =
                    {
                        SevenZip.CoderPropID.DictionarySize,
                        SevenZip.CoderPropID.PosStateBits,
                        SevenZip.CoderPropID.LitContextBits,
                        SevenZip.CoderPropID.LitPosBits,
                        SevenZip.CoderPropID.Algorithm,
                        SevenZip.CoderPropID.NumFastBytes,
                        SevenZip.CoderPropID.MatchFinder,
                        SevenZip.CoderPropID.EndMarker
                    };

                    object[] properties =
                    {
                        (Int32)(dictionary),
                        (Int32)(posStateBits),
                        (Int32)(litContextBits),
                        (Int32)(litPosBits),
                        (Int32)(algorithm),
                        (Int32)(numFastBytes),
                        "bt4",
                        false
                    };

                    SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();
                    encoder.SetCoderProperties(propIDs, properties);
                    encoder.WriteCoderProperties(ms);

                    using (MemoryStream input = new MemoryStream(buffer)) {
                        encoder.Code(input, ms, -1, -1, null);
                    }

                    writer.Write(crc);
                    writer.Write((uint)buffer.Length);
                    writer.Write(VZipFooter);

                    return(ms.ToArray());
                }
        }
All Usage Examples Of SteamKit2.CryptoHelper::CRCHash