CryptoSys API Library Manual

PC1_Hex

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

VB6/VBA 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)

Parameters

strOutput
[out] String to receive the hexadecimal-encoded output.
nMaxChars
[in] Long specifying the maximum number of characters in strOutput.
strInputHex
[in] String containing the input data in hex format.
strKeyHex
[in] String containing the key in hex format.

C/C++ Syntax

long _stdcall PC1_Hex(char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex);

Returns (VB6/C)

Long: 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 strInputHex can be of any length provided strOutput is at least as long. The key strKeyHex can be any length. strOutput and strInputHex 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]

[HOME]   [NEXT: RNG_BytesWithPrompt...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.