How to Run CryptoNets in 2022
This is a post about how to install and run CryptoNets in 2022.
Introduction
More and more companies have built applications based on big data techniques in recent years. To have a well-performance model, collecting data has become a must. However, the consciousness of privacy raises in many people’s minds, and they are less willing to give data to companies. As a result, data protection has become a vital technique to balance the dilemma between big data and data privacy.
In 2016, Microsoft Research published CryptoNets [1], the first paper to infer a CNN model in the encrypted domain. The main idea of CryptoNets is to infer encrypted data in the encrypted domain, and the protocol is under a client who has sensible data and a company that has a CNN model. At the beginning of the protocol, a client encrypts his data with his public key and sends it to the company. Next, when the company receives the encrypted image, he infers the image in the encrypted domain and sends the result back to the client. After the client gets the encrypted result, he decrypts the result with his private key, and now he gets the meaning of the result. Because the whole process is in the encrypted domain, the company doesn’t have any information about this image. As a result, CryptoNets can effectively protect data privacy.
Although CryptoNets is good for beginners to know how to infer data in the encrypted domain, after Microsoft Research released related code in 2019, the code doesn’t be updated anymore. In this post, I will tell you how to run CryptoNets in 2022.
Prerequisites
Before we start, we need the following things:
Visual Studio 2022
Microsoft Research wrote CryptoNets in C#, so we need VS to compile the project. The installation instructions are in the next section.
SEAL Repo
I’ve updated the setting files for VS 2022, so I recommend you clone the branch
cryptonets_with_vs_2022
of my fork.CryptoNets Repo
You can get the repo from here.
NuGet Package command line tool
Following the official manual, we need to pack SEAL Library into a NuGet package file. You can get the command-line tool from here.
MNIST Dataset
You can find the dataset from here. Both training dataset and testing dataset are needed.
Installation Guides
If eveything is set up, let’s get started!
Install visual studio 2022
You need to install VS 2022 with the following requirements:
- Desktop Development with C++
- .Net Desktop Development
- C++ Cmake tools for Windows
- C++ Cmake tools for Linux
- .Net Framework 4.8
- .Net Framework 4.8 targeting pack
- .Net Core 2.1 Runtime (out of support)
Compile SEAL Library (the folloing steps are under SEAL Repo)
Use VS to open
./donet/src/SEALNET.csproj
and accept all review solution actions.Build the following three projects after setting the configuration as
Release
and the platform asx64
../native/src/SEAL.vcxproj
./dotnet/native/SEALNetNative.vcxproj
./dotnet/src/SEALNet.csproj
Put NuGet command-line tool into
./dotnet/nuget
folder.Open
./dotnet/nuget
with CMD and enter the following command to build nuget packages. The SEAL nupkg file is generated under./dotnet/nuget/Release
.nuget pack SEALNet.nuspec -properties Configuration=Release -Verbosity detailed -OutputDir Release
Copy the SEAL nupkg file to the root directory of CryptoNets Repo.
Compile CryptoNets Project (the folloing steps are under CryptoNets Repo)
Use VS to open
./CryptoNets/CryptoNets.sln
and updfatre the .Net Framework version.Follow
Tool -> Nuget Package Manager -> Manage NuGet Packages for Solution
to import SEAL nupkg file.If you cannot find the SEAL nupgk file, you may need to restart visual studio.
Build DataPreprocess and CryptoNets projects after set the configuration as
Debug
and the platform asx64
, .Put the MNIST dataset files into
./bin/x64/Debug/
.
Run CryptoNets (the folloing steps are also under CryptoNets Repo)
- Open CMD and cd to
./bin/x64/Debug
. - Execute
DataPreprocess.exe MNIST
to generateMNIST-28-28-test.txt
for CryptoNets.exe. - Execute
CryptoNets.exe
. This program will train a CNN model first and start to infer images in the encrypted domain.
- Open CMD and cd to
Conclusion
This post showed how to run CryptoNets with visual studio 2022. If you are interested in this research topic, there are other applications you can also try in the CryptoNets repo.