To use CryptoSys API in VB.NET, you call .NET methods instead of VB6 functions.
In almost all cases, a VB6 function like FOO_Barbaz
is replaced by the .NET method Foo.Barbaz
.
The .NET methods generally have fewer parameters and different return values than the equivalent VB6 function.
Long
types in VB6 must be changed to Integer
in VB.NET.
Functions that in VB6 would have output to a pre-dimensioned string or byte array will return that string or byte array directly in VB.NET. For such methods in VB.NET, an error condition is indicated by returning an empty string or byte array.
VB6/VBA
ReDim abDigest(API_MAX_HASH_BYTES - 1) nRet = HASH_Bytes(abDigest(0), API_MAX_HASH_BYTES, abMessage(0), nMsgLen, API_HASH_MD5)
VB.NET
abDigest = Hash.BytesFromBytes(abMessage, HashAlgorithm.Md5)
Most methods in VB.NET are stateless and do not require the creation of an object. These are called in a one-off manner. Those stateful functions in VB6 that use a context handle created by an Init function and closed by a Final function are replaced in VB.NET by objects that must be instantiated and then disposed of. Be careful with error conditions because the VB6 Init functions return zero on error, but the VB.NET Init methods return either True or zero on success.
VB6/VBA
Dim hContext as Long hContext = Foo_Init(...) If hContext = 0 Then nError = Foo_InitError() ... End If For i = 1 To n nRet = Foo_Update(hContext, abBlock(0), nBlockLen) Next nRet = Foo_Final(hContext)
VB.NET
Dim oFoo As Foo = Foo.Instance() nRet = oFoo.InitEncrypt(...) If nRet <> 0 nError = oFoo.ErrCode ... End If For i = 1 To n abBlock = oFoo.Update(abBlock) End If oFoo.Dispose()