forked from bhavya-goyal-22/tflite-model-protector-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt_model.cpp
More file actions
35 lines (26 loc) · 964 Bytes
/
encrypt_model.cpp
File metadata and controls
35 lines (26 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include "TFLiteModelProtector/include/model_protector.hpp"
namespace fs = std::filesystem;
int main(int argc, char* argv[]) {
TFLiteModelProtector model_protector;
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <tflite_model_file>" << std::endl;
return 1;
}
std::string input_file = argv[1];
std::string filename = input_file.substr(0, input_file.find_last_of("."));
std::string encrypted_file = filename + ".enc";
std::vector<uint8_t> key(TFLiteModelProtector::kAesKeyLength);
std::vector<uint8_t> iv(TFLiteModelProtector::kAesIvLength);
model_protector.GenerateKeyAndIv(key, iv);
if (!model_protector.EncryptFile(input_file, encrypted_file)) {
std::cerr << "Encryption failed!" << std::endl;
return 1;
}
std::cout << "Encryption successful!" << std::endl;
std::cout << "Encrypted model saved as: " << encrypted_file << std::endl;
return 0;
}