Home > Language Reference > Classes > StreamCipher

InitCrc32 Method

Sets the encoding/decoding scheme to CRC-32.

Syntax

Public Sub InitCrc32(Optional ByVal lSeed As Long = 0)

ParameterDescription
lSeedInitial checksum value.

Remarks

The InitCrc32 method initializes the stream for CRC-32 checksum computation, and allocates the necessary internal buffers. If the object was already initialized, buffers allocated for the previous encoding scheme are freed, and any pending data are lost.

The lSeed parameter is the initial value for the checksum. Usually, you'll omit this parameter and use the default value, but you can pass the function a result of a previous CRC-32 computation if you need to calculate the checksum of a block that is splitted into several data streams.

At any time, you can retrieve the current checksum value by reading the Digest property. Calling the Flush method resets the checksum to the lSeed value.

The following sample shows how to compute the CRC-32 checksum over a whole file. Actually, data are simply read into a null stream through a StreamCipher object properly initialized.

Public Function Checksum(ByVal iVolRef As Integer, ByRef sFile As String) As Integer
  Dim sc As New StreamCipher
  Dim sn As New StreamNull
  Dim sf As New StreamFile

  sf.Open iVolRef,sFile,hbModeOpenExisting+hbModeReadOnly
  sc.InitCrc32
  Set sc.Source=sf
  sc.Read sn
  sf.Close
  Checksum=sc.Digest
End Function

Note that in this mode, the StreamCipher object acts as a simple pipe. Read and write operations are simply passed on the underlying Source stream, and data are neither altered nor buffered in any way.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A