CryptoSys API Library Manual

PC1_Bytes

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

VB6/VBA Syntax

Public Declare Function PC1_Bytes Lib "diCryptoSys.dll" (ByRef abOutput As Byte, ByRef abData As Byte, ByVal nDataLen As Long, ByRef abKey As Byte, ByVal nKeyLen As Long) As Long

nRet = PC1_Bytes(abOutput(0), abData(0), nDataLen, abKey(0), nKeyLen)

Parameters

abOutput
[out] Byte array of sufficient length to receive the output.
abData
[in] Byte array containing the input data.
nDataLen
[in] Long equal to length of the input data in bytes.
abKey
[in] Byte array containing the key.
nKeyLen
[in] Long equal to length of the key in bytes.

C/C++ Syntax

long _stdcall PC1_Bytes(unsigned char *output, unsigned char *input, long nbytes, unsigned char *key, long keyBytes);

Returns (VB6/C)

Long: 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 abData can be of any length provided abOutput is at least as long. The key abKey can be any length. abOutput and abData may be the same.

VB6/VBA users: Note the '(0)' after the byte array variables.

Example

    Dim abKey() As Byte
    Dim abInput() As Byte
    Dim abOutput() 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 abOutput(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(abOutput(0), abInput(0), nDataLen, abKey(0), nKeyLen)
    Debug.Print "CT="; cnvHexStrFromBytes(abOutput)
    Debug.Print "OK="; sCorrect
    
    ' Now decipher just by calling again. Use same output as input.
    nRet = PC1_Bytes(abOutput(0), abOutput(0), nDataLen, abKey(0), nKeyLen)
    Debug.Print "P'="; cnvHexStrFromBytes(abOutput)

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]

[HOME]   [NEXT: PC1_File...]

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