Home > Language Reference > Classes > StreamCipher

InitMD5 Method

Sets the encoding/decoding scheme to MD5.

Syntax

Public Sub InitMD5()

Remarks

The InitMD5 method initializes the stream for MD5 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 message digest is not available until the Flush method is called. Therefore, calling the Digest property before all data have been read or written and before the stream is flushed returns an unpredictable value. Once the Flush method is called, the algorithm is reset to its initial state.

The following sample shows how to compute the MD5 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.InitMD5
  Set sc.Source=sf
  sc.Read sn
  sc.Flush
  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