Here are a list of things required:

  1. SQLCipher: https://github.com/sqlcipher/sqlcipher
  2. tclsh: https://www.tcl.tk/software/tcltk/download.html
  3. perl: http://strawberryperl.com/download/5.30.1.1/strawberry-perl-5.30.1.1-64bit.msi
  4. CMake
  5. MSVC
  6. OpenSSL (if linked against openssl): https://github.com/openssl/openssl
  7. libtommath (if linked against tomcrypt): https://github.com/libtom/libtommath
  8. libtomcrypt (if linked against tomcrypt): https://github.com/libtom/libtomcrypt

    Environment setup

  9. Open Windows terminal or just CMD.exe
  10. Run the vc env setup script vcvars64.bat from msvc installation location, such as D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build

Link against OpenSSL

Openssl

as previously stated in https://blog.2cn.in/index.php/archives/libcurl.html#toc-3BuildOpenSSL, run the following command:

perl Configure VC-WIN64A --prefix=E:\openssl\builds no-shared
nmake
nmake install

If everything goes right, your openssl is correctly built and copied to E:\openssl\builds.

tclsh

The tcl extension building can be disabled via disable-tcl in Linux, but unfortunately, it can't be disabled in MSVC, we have to build it from source code. ActiveTcl won't help.

Luckily, there is an official document about all the required steps to build the tclsh and here is how:

cd PATH/TO/TCLSH/SOURCE
cd win
nmake /f makefile.vc release

// assuming you'd like to install it to the default location
nmake /f makefile.vc INSTALLDIR=c:\Tcl install  

copy c:\Tcl\bin\tclsh86t.exe c:\Tcl\bin\tclsh.exe

// now recompile it statically
nmake /f makefile.vc OPTS=nothreads,static shell

// change the release folder accordingly
copy Release_AMD64_VC1937\tcl86s.lib c:\Tcl\lib 
set TCLDIR=c:\Tcl
set PATH=%PATH%;c:\tcl\bin

This should do everything for you including renaming files and setup environment variables.

SQLCipher

Do not close the terminal used in the tclsh, switch directory into where sqlcipher is located and continue.

nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_HAS_CODEC -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1 -IE:\openssl\builds\include" CCOPTS="-DSTATIC_BUILD" LIBTCL="tcl86s.lib netapi32.lib user32.lib" LTLINKOPTS="-LIBPATH:E:\openssl\builds\lib\ libcrypto.lib libssl.lib user32.lib Ws2_32.lib Advapi32.lib Crypt32.lib"

Yes, that's right! This command is all your need given the every hard work we have done. The compiled sqlite3.dll and sqlite3.lib should be in the same folder after compiling.


Link against tomcrypt

It's so much easier to link against libtomcrypt and the final executable is also much smaller. It's now the recommended way to encrypt sqlite database IMO.

libtommath

Compiling libtom* is quite easy.

nmake /f makefile.msvc

should be enough.

libtomcrypt

The same as libtommath.

Sqlcipher

Here we go:

nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_HAS_CODEC -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1 -DSQLCIPHER_CRYPTO_LIBTOMCRYPT -I..\libtommath -I..\libtomcrypt\src\headers" CCOPTS="-DSTATIC_BUILD" LIBTCL="tcl86s.lib netapi32.lib user32.lib" LTLINKOPTS="-LIBPATH:..\libtommath -LIBPATH:..\libtomcrypt tommath.lib tomcrypt.lib user32.lib Ws2_32.lib Advapi32.lib"

assuming libtom* are in the same parent directory as sqlcipher. If not, please change include and lib path to your value.