CryptoSys API Library Manual

PC1_Bytes

Enciphers an array of Bytes in one step using the RC4-compatible 'PC1' algorithm.

VBA/VB6 Syntax

Public Declare Function PC1_Bytes Lib "diCryptoSys.dll" (ByRef lpOutput As Byte, ByRef lpData As Byte, ByVal nDataLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long) As Long

nRet = PC1_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), nKeyLen) ' Note the "(0)" after the byte array parameters

C/C++ Syntax

long __stdcall PC1_Bytes(unsigned char *lpOutput, unsigned char *lpInput, long nBytes, unsigned char *lpKey, long nKeyBytes);

Parameters

lpOutput
[out] array of sufficient length to receive the output.
lpInput
[in] array containing the input data.
nBytes
[in] equal to length of the input data in bytes.
lpKey
[in] array containing the key.
nKeyBytes
[in] equal to length of the key in bytes.

Returns (VBA/C)

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

.NET Equivalent

Pc1.Encrypt Method (Byte[], Byte[])

COM/ASP Equivalent

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

See pc1.EncryptHex.

Remarks

The input data lpData can be of any length provided lpOutput is at least as long. The key lpKey can be any length. lpOutput and lpData may be the same.

Example

    Dim abKey() As Byte
    Dim abInput() As Byte
    Dim lpOutput() As Byte
    Dim nRet As Long
    Dim nDataLen As Long
    Dim nKeyLen As Long
    Dim sCorrect As String
    
    abKey = cnvBytesFromHexStr("0123456789abcdef")
    abInput = cnvBytesFromHexStr("0123456789abcdef")
    sCorrect = "75b7878099e0c596"
    
    ReDim lpOutput(UBound(abInput))
    nDataLen = UBound(abInput) - LBound(abInput) + 1
    nKeyLen = UBound(abKey) - LBound(abKey) + 1
    
    Debug.Print "KY=" & cnvHexStrFromBytes(abKey)
    Debug.Print "PT=" & cnvHexStrFromBytes(abInput)
    ' Encipher using PC1
    nRet = PC1_Bytes(lpOutput(0), abInput(0), nDataLen, abKey(0), nKeyLen)
    Debug.Print "CT=" & cnvHexStrFromBytes(lpOutput)
    Debug.Print "OK=" & sCorrect
    
    ' Now decipher just by calling again. Use same output as input.
    nRet = PC1_Bytes(lpOutput(0), lpOutput(0), nDataLen, abKey(0), nKeyLen)
    Debug.Print "P'=" & cnvHexStrFromBytes(lpOutput)

This should result in output as follows:

KY=0123456789ABCDEF
PT=0123456789ABCDEF
CT=75B7878099E0C596
OK=75b7878099e0c596
P'=0123456789ABCDEF

See Also

PC1_File PC1_Hex

[Contents] [Index]

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

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