Enciphers an array of Bytes in one step using the RC4-compatible 'PC1' algorithm.
VB6/VBA
Debug.Print "Testing PC1_Bytes ..." 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)
Output
Testing PC1_Bytes ... KY= 0123456789ABCDEF PT= 0123456789ABCDEF CT= 75B7878099E0C596 OK= 75b7878099e0c596 P'= 0123456789ABCDEF
VB.NET
Console.WriteLine("Testing PC1_Bytes ...") Dim abKey() As Byte Dim abInput() As Byte Dim abOutput() As Byte ''Dim nRet As Integer ''Dim nDataLen As Integer ''Dim nKeyLen As Integer Dim sCorrect As String abKey = Cnv.FromHex("0123456789abcdef") abInput = Cnv.FromHex("0123456789abcdef") sCorrect = "75b7878099e0c596" ''ReDim abOutput(UBound(abInput)) ''nDataLen = UBound(abInput) - LBound(abInput) + 1 ''nKeyLen = UBound(abKey) - LBound(abKey) + 1 Console.WriteLine("KY=" & " " & Cnv.ToHex(abKey)) Console.WriteLine("PT=" & " " & Cnv.ToHex(abInput)) ' Encipher using PC1 abOutput = Pc1.Encrypt(abInput, abKey) Console.WriteLine("CT=" & " " & Cnv.ToHex(abOutput)) Console.WriteLine("OK=" & " " & sCorrect) ' Now decipher just by calling again. Use same output as input. abOutput = Pc1.Encrypt(abOutput, abKey) Console.WriteLine("P'=" & " " & Cnv.ToHex(abOutput))
[Contents]