Enciphers a file using the RC4-compatible 'PC1' algorithm. The key is passed as an array of bytes.
Public Declare Function PC1_File Lib "diCryptoSys.dll"
(ByVal strFileOut As String, ByVal strFileIn As String,
ByRef lpKey As Byte, ByVal nKeyLen As Long) As Long
nRet = PC1_File(strFileOut, strFileIn, abKey(0), nKeyLen)
long __stdcall PC1_File(char *szFileOut, char *szFileIn, unsigned char *lpKey, long nKeyBytes);
If successful, the return value is 0; otherwise it returns a non-zero error code.
The key array lpKey can be any length. The output file szFileOut will be overwritten without warning. The input and output filenames must not be the same.
Const MY_PATH As String = "C:\Test\" Dim abKey(5) As Byte Dim strFileOut As String Dim strFileIn As String Dim strFileChk As String Dim nRet As Long Debug.Print "Test_PC1_File..." ' Construct full path names to files strFileIn = MY_PATH & "hello.txt" strFileOut = MY_PATH & "hello.pc1.enc.dat" strFileChk = MY_PATH & "hello.pc1.chk.txt" ' Setup the 6-byte key "abcxyz" abKey(0) = Asc("a") abKey(1) = Asc("b") abKey(2) = Asc("c") abKey(3) = Asc("x") abKey(4) = Asc("y") abKey(5) = Asc("z") ' Encipher plaintext file nRet = PC1_File(strFileOut, strFileIn, abKey(0), 6&) Debug.Print "PC1_File returns " & nRet ' Now decipher just by repeating nRet = PC1_File(strFileChk, strFileOut, abKey(0), 6&) Debug.Print "PC1_File returns " & nRet
This should result in output as follows:
Test_PC1_File... PC1_File returns 0 PC1_File returns 0