CryptoSys PKI Pro Manual

Converting VB6 to VB.NET

To use CryptoSys PKI Pro 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. See the List of .NET Methods and Cross-reference between Functions and .NET Methods.

All methods in VB.NET are "all-in-one" stateless methods and do not require the creation of an object. They are all called in a one-off manner.

Long types in VB6 must be changed to Integer in VB.NET. All integers in CryptoSys PKI Pro are 32-bit signed integers. You will get an exception or garbage results if you use a VB.NET Long type.

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(PKI_MAX_HASH_BYTES - 1)
nRet = HASH_Bytes(abDigest(0), PKI_MAX_HASH_BYTES, abMessage(0), nMsgLen, PKI_HASH_MD5)

VB.NET

abDigest = Hash.BytesFromBytes(abMessage, HashAlgorithm.Md5)

Annotated example:

VB6/VBA

 1 Debug.Print "Testing HASH_HexFromHex ..."
 2 Dim strDigest As String
 3 Dim nRet As Long
 4 Dim strData As String
 5 strDigest = String(PKI_SHA1_CHARS, " ")
 6 strData = "616263"
 7 nRet = HASH_HexFromHex(strDigest, Len(strDigest), strData, PKI_HASH_SHA1)
 8 Debug.Print strDigest

Comments:

Output

Testing HASH_HexFromHex ...
a9993e364706816aba3e25717850c26c9cd0d89d

VB.NET

 1 Console.WriteLine("Testing HASH_HexFromHex ...")
 2 Dim strDigest As String
 3 ''Dim nRet As Integer
 4 Dim strData As String
 5 ''strDigest = String(PKI_SHA1_CHARS, " ")
 6 strData = "616263"
 7 strDigest = Hash.HexFromHex(strData, HashAlgorithm.Sha1)
 8 Console.WriteLine(strDigest)

Comments:

[Contents] [Index]

[PREV: Converting strings to bytes and vice versa...]   [Contents]   [Index]   
   [NEXT: Using with Classic Visual Basic VB6 and VBA...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.