CryptoSys API examples VB6 to VB.NET

PC1_Hex

Enciphers data encoded in hex format in one step using the RC4-compatible 'PC1' algorithm.

VB6/VBA

Debug.Print "Testing PC1_Hex ..."
Dim nRes As Long
Dim strKey As String
Dim strInput As String
Dim strOutput As String
Dim strCorrect As String
Dim strCheck As String

' Test vector 3
strKey = "ef012345"
strInput = "00000000000000000000"
strCorrect = "d6a141a7ec3c38dfbd61"

Debug.Print "KY=", strKey
Debug.Print "PT=", strInput
' Encipher using PC1 in hex mode
strOutput = String(Len(strInput), " ")
nRes = PC1_Hex(strOutput, Len(strOutput), strInput, strKey)
Debug.Print "CT=", strOutput
Debug.Print "OK=", strCorrect

' Now decipher just by calling again.
strCheck = String(Len(strInput), " ")
nRes = PC1_Hex(strCheck, Len(strCheck), strOutput, strKey)
Debug.Print "P'=", strCheck

Output

Testing PC1_Hex ...
KY=   ef012345
PT=   00000000000000000000
CT=   D6A141A7EC3C38DFBD61
OK=   d6a141a7ec3c38dfbd61
P'=   00000000000000000000

VB.NET

Console.WriteLine("Testing PC1_Hex ...")
''Dim nRes As Integer
Dim strKey As String
Dim strInput As String
Dim strOutput As String
Dim strCorrect As String
Dim strCheck As String

' Test vector 3
strKey = "ef012345"
strInput = "00000000000000000000"
strCorrect = "d6a141a7ec3c38dfbd61"

Console.WriteLine("KY=" & " " & strKey)
Console.WriteLine("PT=" & " " & strInput)
' Encipher using PC1 in hex mode
''strOutput = String(Len(strInput), " ")
strOutput = Pc1.Encrypt(strInput, strKey)
Console.WriteLine("CT=" & " " & strOutput)
Console.WriteLine("OK=" & " " & strCorrect)

' Now decipher just by calling again.
''strCheck = String(Len(strInput), " ")
strCheck = Pc1.Encrypt(strOutput, strKey)
Console.WriteLine("P'=" & " " & strCheck)

[Contents]

[HOME]   [NEXT: RNG_Initialize...]

Copyright © 2009-20 D.I. Management Services Pty Ltd. All rights reserved.