CryptoSys API Library Manual

CIPHER_StreamFile

Enciphers data in a file using specified stream cipher.

VBA/VB6 Syntax

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)

C/C++ Syntax

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);

Parameters

szFileOut
[in] with the full path name of the output file to be created.
szFileIn
[in] with the full path name of the input file to be processed.
lpKey
[in] array containing the key.
nKeyLen
[in] specifying the length of the key in bytes.
lpIV
[in] array containing the initialization vector (IV, nonce), if required.
nIvLen
[in] specifying the length of the IV in bytes.
nCounter
[in] the value of the counter (ChaCha20 only).
nOptions
[in] option flags:
Select one of the following:
API_SC_ARCFOUR to use ARCFOUR (RC4)
API_SC_SALSA20 to use Salsa20
API_SC_CHACHA20 to use ChaCha20

Returns (VBA/C)

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

.NET Equivalent

CipherStream.File Method

C++ (STL) Equivalent

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)

Python Equivalent

static CipherStream.file(fileout, filein, key, iv, alg, counter=0)

Remarks

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.

Example

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)"

See Also

CIPHER_StreamBytes CIPHER_StreamInit

[Contents] [Index]

[PREV: CIPHER_StreamBytes...]   [Contents]   [Index]   
   [NEXT: CIPHER_StreamFinal...]

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