CryptoSys API Library Manual

PC1_Hex

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

VBA/VB6 Syntax

Public Declare Function PC1_Hex Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal strInputHex As String, ByVal strKeyHex As String) As Long

nRet = PC1_Hex(strOutput, nMaxChars, strInputHex, strKeyHex)

C/C++ Syntax

long __stdcall PC1_Hex(char *szOutput, long nMaxChars, const char *szInputHex, const char *szKeyHex);

Parameters

szOutput
[out] to receive the hexadecimal-encoded output.
nMaxChars
[in] specifying the maximum number of characters in szOutput.
szInputHex
[in] containing the input data in hex format.
szKeyHex
[in] containing the key in hex format.

Returns (VBA/C)

If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Pc1.Encrypt Method (String, String)

COM/ASP Equivalent

pc1.EncryptHex
Public Function EncryptHex(ByVal sInputHex As String, ByVal strHexKey As String) As String

See pc1.EncryptHex.

Remarks

All hex parameters must be an even number of hexadecimal digits. The input data szInputHex can be of any length provided szOutput is at least as long. The key szKeyHex can be any length. szOutput and szInputHex should be different variables.

Example

    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

This should result in output as follows:

KY=ef012345
PT=00000000000000000000
CT=D6A141A7EC3C38DFBD61
OK=d6a141a7ec3c38dfbd61
P'=00000000000000000000

See Also

PC1_Bytes PC1_File

[Contents] [Index]

[PREV: PC1_File...]   [Contents]   [Index]   
   [NEXT: PRF_Bytes...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.