Enciphers data in a file using specified stream cipher.
Public Declare Function CIPHER_StreamFile Lib "diCryptoSys.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIvLen As Long, ByVal nCounter As Long, ByVal nOptions As Long) As Long
nRet = CIPHER_StreamFile(strFileOut, strFileIn, abKey(0), nKeyLen, abIV(0), nIvLen, nCounter, nOptions)
long __stdcall CIPHER_StreamFile(const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long nKeyLen, unsigned char *lpIV, long nIvLen, long nCounter, long nOptions);
If successful, the return value is zero; otherwise it returns a nonnegative error code.
static int crsysapi::CipherStream::File (const std::string &fileOut, const std::string &fileIn, const bvec_t &key, const bvec_t &iv, Alg alg, int counter=0)
static CipherStream.file(fileout, filein, key, iv, alg, counter=0)
This performs a one-off encryption of a file using the specified stream cipher. The key and IV are passed as byte arrays. The output file will be exactly the same length as the input. The output file must not be the same as the input file.
null
for IV.Dim nRet As Long Dim strFileIn As String Dim strFileOut As String Dim abKey() As Byte Dim abInput() As Byte Dim abIV() As Byte Dim nKeyLen As Long Dim nIvLen As Long Dim nCounter As Long ' Obtain parameters in byte array format abKey = cnvBytesFromHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") abIV = cnvBytesFromHexStr("000000000000004a00000000") nCounter = 1 nKeyLen = UBound(abKey) + 1 nIvLen = UBound(abIV) + 1 Debug.Print "Key: " & cnvHexStrFromBytes(abKey) Debug.Print "IV: " & cnvHexStrFromBytes(abIV) Debug.Print "Counter: " & nCounter ' Encipher plaintext file strFileIn = "sunscreen.txt" strFileOut = "sunscreen-chacha.dat" nRet = CIPHER_StreamFile(strFileOut, strFileIn, abKey(0), nKeyLen, abIV(0), nIvLen, nCounter, API_SC_CHACHA20) Debug.Print "CIPHER_StreamFile returns " & nRet & " (expecting 0)"
CIPHER_StreamBytes
CIPHER_StreamInit