CryptoSys API Library Manual

Example: Blowfish.Dispose  Blowfish.ErrCode  Blowfish.InitEncrypt  Blowfish.Instance  Blowfish.Update 

[VB6 equivalent: BLF_Update]

' Contrived example to encrypt sample blocks in CBC mode
Dim abBlock(7) As Byte
Dim abKey() As Byte
Dim abInitV() As Byte
Dim nRet As Integer
Dim i As Integer
Dim j As Integer
Dim oBlowfish As Blowfish = Blowfish.Instance()

' Specify a key and its length
abKey = Cnv.FromHex("FEDCBA9876543210")

' And an IV (length is assumed to be 8 bytes)
abInitV = Cnv.FromHex("0123456789abcdef")

' Initialise the context
nRet = oBlowfish.InitEncrypt(abKey, Mode.CBC, abInitV)
If nRet <> 0 Then
    nRet = oBlowfish.ErrCode
    Console.WriteLine("BFL_Init Failed: " & General.ErrorLookup(nRet))
    Exit Sub
End If

Console.WriteLine("KY=" & " " & Cnv.ToHex(abKey))
Console.WriteLine("IV=" & " " & Cnv.ToHex(abInitV))

' Create some test blocks and encrypt them
For i = 1 To 4
    For j = 0 To 7
        abBlock(j) = CByte(i)
    Next
    Console.WriteLine("PT(" & i & ")=" & " " & Cnv.ToHex(abBlock))
    abBlock = oBlowfish.Update(abBlock)
    Console.WriteLine("CT(" & i & ")=" & " " & Cnv.ToHex(abBlock))
Next

' Clear the context
oBlowfish.Dispose()

See Also:
Blowfish.Update Method (Byte[])

[Contents] [Index]

[PREV: Example: Blowfish.Decrypt ...]   [Contents]   [Index]   
   [NEXT: Example: Blowfish.Dispose ...]

Copyright © 2001-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-05-20T13:01:10Z.