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:
strDigest
or else! nRet = 0
indicates success (for this function). PKI_HASH_SHA1
flag to specify hash algorithm option. 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:
strDigest.Length > 0
indicates success.HashAlgorithm
property to specify hash algorithm option.