Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90f4549da0 | ||
|
|
0a9bb829c3 | ||
|
|
7783fcee38 | ||
|
|
ed7a1206a1 | ||
|
|
2ed7ab751b | ||
|
|
edc1f2243d | ||
|
|
78236d5b97 | ||
|
|
be340c7d2e | ||
|
|
c61ab71d36 | ||
|
|
7429a186d4 | ||
|
|
68d24e678a |
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build/*
|
||||||
|
include/*
|
||||||
|
lib/*
|
||||||
|
Pub/*
|
||||||
|
.*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
set(PROJECT_NAME Parser)
|
set(PROJECT_NAME Parser)
|
||||||
project(${PROJECT_NAME})
|
project(${PROJECT_NAME})
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
@@ -18,20 +18,21 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE PARSER_LIBRARY=)
|
|||||||
|
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
target_link_libraries(${PROJECT_NAME} matio sqlite3)
|
find_package(OpenSSL REQUIRED)
|
||||||
|
target_link_libraries(${PROJECT_NAME} matio sqlite3 ${OPENSSL_LIBRARIES})
|
||||||
elseif(MSVC)
|
elseif(MSVC)
|
||||||
target_link_libraries(${PROJECT_NAME} libmatio sqlite3)
|
target_link_libraries(${PROJECT_NAME} libmatio sqlite3)
|
||||||
elseif(MINGW)
|
elseif(MINGW)
|
||||||
target_link_libraries(${PROJECT_NAME} matio sqlite3)
|
target_link_libraries(${PROJECT_NAME} matio sqlite3)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(BBENC_INCLUDE_FILES parser_global.h Parser.h
|
install(FILES src/parser_global.h DESTINATION include/Parser)
|
||||||
ShotList/ShotList.h
|
install(FILES src/Parser.h DESTINATION include/Parser)
|
||||||
MatLab/MatlabCreator.h MatLab/MatlabOpener.h
|
install(DIRECTORY src/ShotList/ DESTINATION include/Parser/ShotList FILES_MATCHING PATTERN "ShotList.h")
|
||||||
Data/Arraypointer.h Data/CEData.h Data/ConfigHeader.h Data/MetaData.h Data/MovementData.h Data/PatientData.h Data/TemperatureData.h Data/AScanData.h Data/ElectricIndex.h Data/ElementIndex.h Data/GeometryIndex.h Data/Hardwareinfomation.h Data/OneTasAScanData.h Data/TasElementIndex.h Data/TasIndex.h Data/CEMeasuredData.h)
|
install(DIRECTORY src/MatLab/ DESTINATION include/Parser/MatLab FILES_MATCHING PATTERN "*.h")
|
||||||
set(INCLUDE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/Parser/")
|
install(DIRECTORY src/Data/ DESTINATION include/Parser/Data FILES_MATCHING PATTERN "*.h")
|
||||||
|
install(FILES cmake/ParserConfig.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake)
|
||||||
foreach(file ${BBENC_INCLUDE_FILES})
|
install(FILES thirdParty/lib/libmatio.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/ RENAME libmatio.so.11)
|
||||||
execute_process( COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/src/${file}" ${INCLUDE_OUTPUT_PATH}${file})
|
install(FILES thirdParty/lib/libsqlite3.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/ RENAME libsqlite3.so.0)
|
||||||
endforeach( file )
|
install(TARGETS Parser RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ set(Parser_BUILD_VERSION 0)
|
|||||||
get_filename_component(Parser_DIR "${CMAKE_CURRENT_LIST_DIR}/" PATH)
|
get_filename_component(Parser_DIR "${CMAKE_CURRENT_LIST_DIR}/" PATH)
|
||||||
set(Parser_INCLUDE_DIRS "${Parser_DIR}/include/" "${Parser_DIR}/include/Parser/")
|
set(Parser_INCLUDE_DIRS "${Parser_DIR}/include/" "${Parser_DIR}/include/Parser/")
|
||||||
add_library(Parser SHARED IMPORTED)
|
add_library(Parser SHARED IMPORTED)
|
||||||
set_target_properties(Parser PROPERTIES IMPORTED_LOCATION "${Parser_DIR}/bin/libParser.so")
|
set_target_properties(Parser PROPERTIES IMPORTED_LOCATION "${Parser_DIR}/lib/libParser.so")
|
||||||
add_library(sqlite3 SHARED IMPORTED)
|
add_library(sqlite3 SHARED IMPORTED)
|
||||||
set_property(TARGET sqlite3 APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
|
set_property(TARGET sqlite3 APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
|
||||||
set_target_properties(sqlite3 PROPERTIES IMPORTED_LOCATION_DEBUG "${Parser_DIR}/bin/libsqlite3.so.0")
|
set_target_properties(sqlite3 PROPERTIES IMPORTED_LOCATION_DEBUG "${Parser_DIR}/lib/libsqlite3.so.0")
|
||||||
add_library(matio SHARED IMPORTED)
|
add_library(matio SHARED IMPORTED)
|
||||||
set_property(TARGET matio APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
|
set_property(TARGET matio APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
|
||||||
set_target_properties(matio PROPERTIES IMPORTED_LOCATION_DEBUG "${Parser_DIR}/bin/libmatio.so.11")
|
set_target_properties(matio PROPERTIES IMPORTED_LOCATION_DEBUG "${Parser_DIR}/lib/libmatio.so.11")
|
||||||
#set(Parser_Libraries Parser matio sqlite3)
|
#set(Parser_Libraries Parser matio sqlite3)
|
||||||
|
|
||||||
set(Parser_FOUND TRUE)
|
set(Parser_FOUND TRUE)
|
||||||
|
|||||||
@@ -95,6 +95,16 @@ void MetaData::setDacDelay(double aDacDelay)
|
|||||||
mDacDelay = aDacDelay;
|
mDacDelay = aDacDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double MetaData::getCEMeasuredDacDelay() const
|
||||||
|
{
|
||||||
|
return mCEMeasuredDacDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MetaData::setCEMeasuredDacDelay(double aCEMeasuredDacDelay)
|
||||||
|
{
|
||||||
|
mCEMeasuredDacDelay = aCEMeasuredDacDelay;
|
||||||
|
}
|
||||||
|
|
||||||
double MetaData::getFilterByPass() const
|
double MetaData::getFilterByPass() const
|
||||||
{
|
{
|
||||||
return mFilterByPass;
|
return mFilterByPass;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
unsigned short getAperturePositionNumber() const;
|
unsigned short getAperturePositionNumber() const;
|
||||||
TimeStampsPointer getTimeStamps() const;
|
TimeStampsPointer getTimeStamps() const;
|
||||||
double getDacDelay() const;
|
double getDacDelay() const;
|
||||||
|
double getCEMeasuredDacDelay() const;
|
||||||
double getFilterByPass() const;
|
double getFilterByPass() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -41,6 +42,7 @@ private:
|
|||||||
void setAperturePositionNumber(unsigned short aAperturePositionNumber);
|
void setAperturePositionNumber(unsigned short aAperturePositionNumber);
|
||||||
void setTimeStamps(TimeStampsPointer aTimeStamps);
|
void setTimeStamps(TimeStampsPointer aTimeStamps);
|
||||||
void setDacDelay(double aDacDelay);
|
void setDacDelay(double aDacDelay);
|
||||||
|
void setCEMeasuredDacDelay(double aCEMeasuredDacDelay);
|
||||||
void setFilterByPass(double aFilterByPass);
|
void setFilterByPass(double aFilterByPass);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -53,6 +55,7 @@ private:
|
|||||||
unsigned short mAperturePositionNumber;
|
unsigned short mAperturePositionNumber;
|
||||||
TimeStampsPointer mTimeStamps;
|
TimeStampsPointer mTimeStamps;
|
||||||
double mDacDelay;
|
double mDacDelay;
|
||||||
|
double mCEMeasuredDacDelay;
|
||||||
double mFilterByPass;
|
double mFilterByPass;
|
||||||
|
|
||||||
friend class MetaDataReader;
|
friend class MetaDataReader;
|
||||||
|
|||||||
@@ -25,6 +25,26 @@ std::string PatientData::getPatientName() const
|
|||||||
return mPatientName;
|
return mPatientName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PatientData::setAccessionNumber(const std::string &aAccessionNumber)
|
||||||
|
{
|
||||||
|
mAccessionNumber = aAccessionNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PatientData::getAccessionNumber() const
|
||||||
|
{
|
||||||
|
return mAccessionNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PatientData::setStudyUID(const std::string &aPatientStudyUID)
|
||||||
|
{
|
||||||
|
mStudyUID = aPatientStudyUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PatientData::getStudyUID() const
|
||||||
|
{
|
||||||
|
return mStudyUID;
|
||||||
|
}
|
||||||
|
|
||||||
void PatientData::setReferringPhysicianName(const std::string& aReferringPhysicianName)
|
void PatientData::setReferringPhysicianName(const std::string& aReferringPhysicianName)
|
||||||
{
|
{
|
||||||
mReferringPhysicianName = aReferringPhysicianName;
|
mReferringPhysicianName = aReferringPhysicianName;
|
||||||
@@ -95,6 +115,16 @@ std::string PatientData::getLaterality() const
|
|||||||
return mLaterality;
|
return mLaterality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PatientData::setModality(const std::string& aModality)
|
||||||
|
{
|
||||||
|
mModality = aModality;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PatientData::getModality() const
|
||||||
|
{
|
||||||
|
return mModality;
|
||||||
|
}
|
||||||
|
|
||||||
void PatientData::setIsEmptyData(bool aIsEmptyData)
|
void PatientData::setIsEmptyData(bool aIsEmptyData)
|
||||||
{
|
{
|
||||||
mIsEmptyData = aIsEmptyData;
|
mIsEmptyData = aIsEmptyData;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ public:
|
|||||||
PatientData();
|
PatientData();
|
||||||
std::string getPatientID() const;
|
std::string getPatientID() const;
|
||||||
std::string getPatientName() const;
|
std::string getPatientName() const;
|
||||||
|
std::string getAccessionNumber() const;
|
||||||
|
std::string getStudyUID() const;
|
||||||
std::string getReferringPhysicianName() const;
|
std::string getReferringPhysicianName() const;
|
||||||
std::string getInstituationName() const;
|
std::string getInstituationName() const;
|
||||||
std::string getInstituationAddress() const;
|
std::string getInstituationAddress() const;
|
||||||
@@ -18,11 +20,14 @@ public:
|
|||||||
std::string getPatientSex() const;
|
std::string getPatientSex() const;
|
||||||
std::string getPatientBirthDate();
|
std::string getPatientBirthDate();
|
||||||
std::string getLaterality() const;
|
std::string getLaterality() const;
|
||||||
|
std::string getModality() const;
|
||||||
bool getIsEmptyData() const;
|
bool getIsEmptyData() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setPatientID(const std::string& aPatientID);
|
void setPatientID(const std::string& aPatientID);
|
||||||
void setPatientName(const std::string& aPatientName);
|
void setPatientName(const std::string& aPatientName);
|
||||||
|
void setAccessionNumber(const std::string& aAccessionNumber);
|
||||||
|
void setStudyUID(const std::string& aPatientStudyUID);
|
||||||
void setReferringPhysicianName(const std::string& aReferringPhysicianName);
|
void setReferringPhysicianName(const std::string& aReferringPhysicianName);
|
||||||
void setInstituationName(const std::string& aInstituationName);
|
void setInstituationName(const std::string& aInstituationName);
|
||||||
void setInstituationAddress(const std::string& aInstituationAddress);
|
void setInstituationAddress(const std::string& aInstituationAddress);
|
||||||
@@ -30,11 +35,14 @@ private:
|
|||||||
void setPatientSex(const std::string& aPatientSex);
|
void setPatientSex(const std::string& aPatientSex);
|
||||||
void setPatientBirthDate(const std::string& aPatientBirthDate);
|
void setPatientBirthDate(const std::string& aPatientBirthDate);
|
||||||
void setLaterality(const std::string& aLaterality);
|
void setLaterality(const std::string& aLaterality);
|
||||||
|
void setModality(const std::string& aModality);
|
||||||
void setIsEmptyData(bool aIsEmptyData);
|
void setIsEmptyData(bool aIsEmptyData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mPatientID;
|
std::string mPatientID;
|
||||||
std::string mPatientName;
|
std::string mPatientName;
|
||||||
|
std::string mAccessionNumber;
|
||||||
|
std::string mStudyUID;
|
||||||
std::string mReferringPhysicianName;
|
std::string mReferringPhysicianName;
|
||||||
std::string mInstituationName;
|
std::string mInstituationName;
|
||||||
std::string mInstituationAddress;
|
std::string mInstituationAddress;
|
||||||
@@ -42,6 +50,7 @@ private:
|
|||||||
std::string mPatientSex;
|
std::string mPatientSex;
|
||||||
std::string mPatientBirthDate;
|
std::string mPatientBirthDate;
|
||||||
std::string mLaterality;
|
std::string mLaterality;
|
||||||
|
std::string mModality;
|
||||||
bool mIsEmptyData;
|
bool mIsEmptyData;
|
||||||
|
|
||||||
friend class PatientDataReader;
|
friend class PatientDataReader;
|
||||||
|
|||||||
@@ -162,6 +162,15 @@ MetaData MetaDataReader::getMetaDataFromHJ(const std::string& aConfigBinPath, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(jsonObj.contains("CEM AMC Board Config"))
|
||||||
|
{
|
||||||
|
nlohmann::json ceMeasuredInfo = jsonObj.at("CEM AMC Board Config");
|
||||||
|
if(ceMeasuredInfo.contains("DAC Delay"))
|
||||||
|
{
|
||||||
|
result.setCEMeasuredDacDelay(ceMeasuredInfo.at("DAC Delay").get<double>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::ifstream stream;
|
std::ifstream stream;
|
||||||
stream.open(aConfigBinPath, std::ios_base::binary | std::ios::in);
|
stream.open(aConfigBinPath, std::ios_base::binary | std::ios::in);
|
||||||
stream.seekg(aConfigHeader->getTasIndicesPosition(),std::ios::beg);
|
stream.seekg(aConfigHeader->getTasIndicesPosition(),std::ios::beg);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Helper/MatlabHelper.h"
|
#include "Helper/MatlabHelper.h"
|
||||||
#include "Data/ConfigHeader.h"
|
#include "Data/ConfigHeader.h"
|
||||||
#include "Json/json.hpp"
|
#include "Json/json.hpp"
|
||||||
|
#include "Helper/AESEncryptHelper.h"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <matio.h>
|
#include <matio.h>
|
||||||
@@ -65,6 +66,12 @@ PatientData PatientDataReader::getPatientDataFromKIT(const std::string& aFilePat
|
|||||||
//PatientName
|
//PatientName
|
||||||
result.setPatientName(getPatientStringData(patMat,"PatientName"));
|
result.setPatientName(getPatientStringData(patMat,"PatientName"));
|
||||||
|
|
||||||
|
//AccessionNumber
|
||||||
|
result.setAccessionNumber(getPatientStringData(patMat,"AccessionNumber"));
|
||||||
|
|
||||||
|
//StudyUID
|
||||||
|
result.setStudyUID(getPatientStringData(patMat,"StudyUID"));
|
||||||
|
|
||||||
//PatientSex
|
//PatientSex
|
||||||
result.setPatientSex(getPatientStringData(patMat,"PatientSex"));
|
result.setPatientSex(getPatientStringData(patMat,"PatientSex"));
|
||||||
|
|
||||||
@@ -89,7 +96,18 @@ PatientData PatientDataReader::getPatientDataFromHJ(const std::string& aFilePath
|
|||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
nlohmann::json patientObj = jsonObj.at("Patient Info");
|
|
||||||
|
if(!jsonObj.at("Patient Info").is_string())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
patientJsonString = jsonObj.at("Patient Info").get<std::string>();
|
||||||
|
patientJsonString = AESEncryptHelper::decrypt(patientJsonString);
|
||||||
|
if(patientJsonString.empty())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
nlohmann::json patientObj = nlohmann::json::parse(patientJsonString);;
|
||||||
if(patientObj.contains("PatientID"))
|
if(patientObj.contains("PatientID"))
|
||||||
{
|
{
|
||||||
result.setPatientID(patientObj.at("PatientID").get<std::string>());
|
result.setPatientID(patientObj.at("PatientID").get<std::string>());
|
||||||
@@ -139,6 +157,21 @@ PatientData PatientDataReader::getPatientDataFromHJ(const std::string& aFilePath
|
|||||||
{
|
{
|
||||||
result.setLaterality(patientObj.at("Laterality").get<std::string>());
|
result.setLaterality(patientObj.at("Laterality").get<std::string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(patientObj.contains("AccessionNumber"))
|
||||||
|
{
|
||||||
|
result.setAccessionNumber(patientObj.at("AccessionNumber").get<std::string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(patientObj.contains("StudyUID"))
|
||||||
|
{
|
||||||
|
result.setStudyUID(patientObj.at("StudyUID").get<std::string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(patientObj.contains("Modality"))
|
||||||
|
{
|
||||||
|
result.setModality(patientObj.at("Modality").get<std::string>());
|
||||||
|
}
|
||||||
delete[] patientCString;
|
delete[] patientCString;
|
||||||
stream.close();
|
stream.close();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
119
src/Helper/AESEncryptHelper.cpp
Normal file
119
src/Helper/AESEncryptHelper.cpp
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#include "AESEncryptHelper.h"
|
||||||
|
|
||||||
|
#include <openssl/bio.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
#include <openssl/buffer.h>
|
||||||
|
#include <openssl/aes.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// 错误处理宏
|
||||||
|
#define HANDLE_ERROR(cond, msg) \
|
||||||
|
if (cond) { \
|
||||||
|
std::cerr << "Error: " << msg << std::endl; \
|
||||||
|
return std::string(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const unsigned char ENCRYPT_KEY[] = {0x00, 0xa1, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
|
||||||
|
const unsigned char ENCRYPT_IV[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f};
|
||||||
|
|
||||||
|
std::string base64_encode(const std::vector<unsigned char>& data) {
|
||||||
|
BIO *bio, *b64;
|
||||||
|
BUF_MEM *bufferPtr;
|
||||||
|
|
||||||
|
// 创建一个 Base64 编码的 BIO
|
||||||
|
b64 = BIO_new(BIO_f_base64());
|
||||||
|
bio = BIO_new(BIO_s_mem());
|
||||||
|
bio = BIO_push(b64, bio);
|
||||||
|
|
||||||
|
// 设置不换行
|
||||||
|
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
|
||||||
|
|
||||||
|
// 写入数据
|
||||||
|
BIO_write(bio, data.data(), data.size());
|
||||||
|
BIO_flush(bio);
|
||||||
|
|
||||||
|
// 获取编码后的字符串
|
||||||
|
BUF_MEM *bptr;
|
||||||
|
BIO_get_mem_ptr(bio, &bptr);
|
||||||
|
BIO_set_close(bio, BIO_NOCLOSE);
|
||||||
|
|
||||||
|
// 创建字符串
|
||||||
|
std::string base64_str(bptr->data, bptr->length);
|
||||||
|
|
||||||
|
// 释放资源
|
||||||
|
BIO_free_all(bio);
|
||||||
|
|
||||||
|
return base64_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string base64_decode(const std::string& aInput) {
|
||||||
|
BIO* b64 = BIO_new(BIO_f_base64());
|
||||||
|
BIO* bio = BIO_new_mem_buf(aInput.c_str(), -1);
|
||||||
|
bio = BIO_push(b64, bio);
|
||||||
|
|
||||||
|
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); // 去掉换行符
|
||||||
|
|
||||||
|
size_t decode_len = (aInput.size() / 4) * 3;
|
||||||
|
if (aInput[aInput.size() - 1] == '=') decode_len--;
|
||||||
|
if (aInput[aInput.size() - 2] == '=') decode_len--;
|
||||||
|
|
||||||
|
std::string decoded;
|
||||||
|
decoded.resize(decode_len);
|
||||||
|
|
||||||
|
int len = BIO_read(bio, &decoded[0], aInput.size());
|
||||||
|
decoded.resize(len);
|
||||||
|
|
||||||
|
BIO_free_all(bio);
|
||||||
|
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string AESEncryptHelper::encrypt(const std::string &aPlainText){
|
||||||
|
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||||
|
HANDLE_ERROR(ctx == nullptr, "EVP_CIPHER_CTX_new failed");
|
||||||
|
|
||||||
|
// Initialize encryption
|
||||||
|
HANDLE_ERROR(EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), nullptr, ENCRYPT_KEY, ENCRYPT_IV) != 1, "EVP_EncryptInit_ex failed");
|
||||||
|
|
||||||
|
std::vector<unsigned char> ciphertext(aPlainText.size() + EVP_CIPHER_block_size(EVP_aes_128_cbc()));
|
||||||
|
int len;
|
||||||
|
HANDLE_ERROR(EVP_EncryptUpdate(ctx, ciphertext.data(), &len, reinterpret_cast<const unsigned char*>(aPlainText.data()), aPlainText.size()) != 1, "EVP_EncryptUpdate failed");
|
||||||
|
int ciphertext_len = len;
|
||||||
|
|
||||||
|
HANDLE_ERROR(EVP_EncryptFinal_ex(ctx, ciphertext.data() + len, &len) != 1, "EVP_EncryptFinal_ex failed");
|
||||||
|
ciphertext_len += len;
|
||||||
|
|
||||||
|
ciphertext.resize(ciphertext_len);
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
|
return ::base64_encode(ciphertext);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AESEncryptHelper::decrypt(const std::string &aCipherText)
|
||||||
|
{
|
||||||
|
std::string unbase = base64_decode(aCipherText);
|
||||||
|
|
||||||
|
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||||
|
HANDLE_ERROR(ctx == nullptr, "EVP_CIPHER_CTX_new failed");
|
||||||
|
|
||||||
|
// Initialize decryption
|
||||||
|
HANDLE_ERROR(EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), nullptr, ENCRYPT_KEY, ENCRYPT_IV) != 1, "EVP_DecryptInit_ex failed");
|
||||||
|
|
||||||
|
std::vector<unsigned char> plaintext(unbase.size());
|
||||||
|
int len;
|
||||||
|
HANDLE_ERROR(EVP_DecryptUpdate(ctx, plaintext.data(), &len, reinterpret_cast<const unsigned char*>(unbase.data()), unbase.size()) != 1, "EVP_DecryptUpdate failed");
|
||||||
|
int plaintext_len = len;
|
||||||
|
|
||||||
|
HANDLE_ERROR(EVP_DecryptFinal_ex(ctx, plaintext.data() + len, &len) != 1, "EVP_DecryptFinal_ex failed");
|
||||||
|
plaintext_len += len;
|
||||||
|
|
||||||
|
EVP_CIPHER_CTX_free(ctx);
|
||||||
|
return std::string(reinterpret_cast<char*>(plaintext.data()), plaintext_len);
|
||||||
|
}
|
||||||
|
|
||||||
14
src/Helper/AESEncryptHelper.h
Normal file
14
src/Helper/AESEncryptHelper.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef AESENCRYPTHELPER_H
|
||||||
|
#define AESENCRYPTHELPER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
class AESEncryptHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AESEncryptHelper() = delete;
|
||||||
|
|
||||||
|
static std::string encrypt(const std::string& aPlainText);
|
||||||
|
static std::string decrypt(const std::string& aCipherText);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ALAESENCRYPTHELPER_H */
|
||||||
@@ -419,8 +419,8 @@ void MatlabCreatorConvertFp16Private::createInfoMat(std::shared_ptr<Parser> aPar
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t structDims[1] ={1};
|
size_t structDims[1] ={1};
|
||||||
const char* field[7] = {"shotlist","samplenumber","SampleRate","Datatype","MeasurementID","DACDelay","FilterBypass"};
|
const char* field[8] = {"shotlist","samplenumber","SampleRate","Datatype","MeasurementID","DACDelay","CEMeasuredDACDelay","FilterBypass"};
|
||||||
matvar_t* structVar = Mat_VarCreateStruct("MetaData",1,structDims,field,7);
|
matvar_t* structVar = Mat_VarCreateStruct("MetaData",1,structDims,field,8);
|
||||||
//shotList
|
//shotList
|
||||||
std::shared_ptr<ShotList> shotList = aParser->getShotList();
|
std::shared_ptr<ShotList> shotList = aParser->getShotList();
|
||||||
ShotListArray shotListArray = shotList->getShotListArray();
|
ShotListArray shotListArray = shotList->getShotListArray();
|
||||||
@@ -453,6 +453,11 @@ void MatlabCreatorConvertFp16Private::createInfoMat(std::shared_ptr<Parser> aPar
|
|||||||
size_t dacDelayDims[2] ={1,1};
|
size_t dacDelayDims[2] ={1,1};
|
||||||
matvar_t* dacDelayVar = Mat_VarCreate("DACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dacDelayDims,&dacDelay,0);
|
matvar_t* dacDelayVar = Mat_VarCreate("DACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dacDelayDims,&dacDelay,0);
|
||||||
Mat_VarSetStructFieldByName(structVar, "DACDelay", 0, dacDelayVar);
|
Mat_VarSetStructFieldByName(structVar, "DACDelay", 0, dacDelayVar);
|
||||||
|
//CEMeasured DACDelay
|
||||||
|
double ceMeasuredDacDelay = metaData.getCEMeasuredDacDelay();
|
||||||
|
size_t ceMeasuredDacDelayDims[2] ={1,1};
|
||||||
|
matvar_t* ceMeasuredDacDelayVar = Mat_VarCreate("CEMeasuredDACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,ceMeasuredDacDelayDims,&ceMeasuredDacDelay,0);
|
||||||
|
Mat_VarSetStructFieldByName(structVar, "CEMeasuredDACDelay", 0, ceMeasuredDacDelayVar);
|
||||||
//FilterBypass
|
//FilterBypass
|
||||||
double filterByPass = metaData.getFilterByPass();
|
double filterByPass = metaData.getFilterByPass();
|
||||||
size_t filterByPassDims[2] ={1,1};
|
size_t filterByPassDims[2] ={1,1};
|
||||||
|
|||||||
@@ -383,8 +383,8 @@ void MatlabCreatorPrivate::createInfoMat(std::shared_ptr<Parser> aParser, const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t structDims[1] ={1};
|
size_t structDims[1] ={1};
|
||||||
const char* field[7] = {"shotlist","samplenumber","SampleRate","Datatype","MeasurementID","DACDelay","FilterBypass"};
|
const char* field[8] = {"shotlist","samplenumber","SampleRate","Datatype","MeasurementID","DACDelay","CEMeasuredDACDelay","FilterBypass"};
|
||||||
matvar_t* structVar = Mat_VarCreateStruct("MetaData",1,structDims,field,7);
|
matvar_t* structVar = Mat_VarCreateStruct("MetaData",1,structDims,field,8);
|
||||||
//shotList
|
//shotList
|
||||||
std::shared_ptr<ShotList> shotList = aParser->getShotList();
|
std::shared_ptr<ShotList> shotList = aParser->getShotList();
|
||||||
ShotListArray shotListArray = shotList->getShotListArray();
|
ShotListArray shotListArray = shotList->getShotListArray();
|
||||||
@@ -417,6 +417,11 @@ void MatlabCreatorPrivate::createInfoMat(std::shared_ptr<Parser> aParser, const
|
|||||||
size_t dacDelayDims[2] ={1,1};
|
size_t dacDelayDims[2] ={1,1};
|
||||||
matvar_t* dacDelayVar = Mat_VarCreate("DACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dacDelayDims,&dacDelay,0);
|
matvar_t* dacDelayVar = Mat_VarCreate("DACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dacDelayDims,&dacDelay,0);
|
||||||
Mat_VarSetStructFieldByName(structVar, "DACDelay", 0, dacDelayVar);
|
Mat_VarSetStructFieldByName(structVar, "DACDelay", 0, dacDelayVar);
|
||||||
|
//CEMeasured DACDelay
|
||||||
|
double ceMeasuredDacDelay = metaData.getCEMeasuredDacDelay();
|
||||||
|
size_t ceMeasuredDacDelayDims[2] ={1,1};
|
||||||
|
matvar_t* ceMeasuredDacDelayVar = Mat_VarCreate("CEMeasuredDACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,ceMeasuredDacDelayDims,&ceMeasuredDacDelay,0);
|
||||||
|
Mat_VarSetStructFieldByName(structVar, "CEMeasuredDACDelay", 0, ceMeasuredDacDelayVar);
|
||||||
//FilterBypass
|
//FilterBypass
|
||||||
double filterByPass = metaData.getFilterByPass();
|
double filterByPass = metaData.getFilterByPass();
|
||||||
size_t filterByPassDims[2] ={1,1};
|
size_t filterByPassDims[2] ={1,1};
|
||||||
|
|||||||
@@ -459,8 +459,8 @@ void MatlabCreatorVariableWindowPrivate::createInfoMat(std::shared_ptr<Parser> a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t structDims[1] ={1};
|
size_t structDims[1] ={1};
|
||||||
const char* field[7] = {"shotlist","samplenumber","SampleRate","Datatype","MeasurementID","DACDelay","FilterBypass"};
|
const char* field[8] = {"shotlist","samplenumber","SampleRate","Datatype","MeasurementID","DACDelay","CEMeasuredDACDelay","FilterBypass"};
|
||||||
matvar_t* structVar = Mat_VarCreateStruct("MetaData",1,structDims,field,7);
|
matvar_t* structVar = Mat_VarCreateStruct("MetaData",1,structDims,field,8);
|
||||||
//shotList
|
//shotList
|
||||||
std::shared_ptr<ShotList> shotList = aParser->getShotList();
|
std::shared_ptr<ShotList> shotList = aParser->getShotList();
|
||||||
ShotListArray shotListArray = shotList->getShotListArray();
|
ShotListArray shotListArray = shotList->getShotListArray();
|
||||||
@@ -493,6 +493,11 @@ void MatlabCreatorVariableWindowPrivate::createInfoMat(std::shared_ptr<Parser> a
|
|||||||
size_t dacDelayDims[2] ={1,1};
|
size_t dacDelayDims[2] ={1,1};
|
||||||
matvar_t* dacDelayVar = Mat_VarCreate("DACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dacDelayDims,&dacDelay,0);
|
matvar_t* dacDelayVar = Mat_VarCreate("DACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,dacDelayDims,&dacDelay,0);
|
||||||
Mat_VarSetStructFieldByName(structVar, "DACDelay", 0, dacDelayVar);
|
Mat_VarSetStructFieldByName(structVar, "DACDelay", 0, dacDelayVar);
|
||||||
|
//CEMeasured DACDelay
|
||||||
|
double ceMeasuredDacDelay = metaData.getCEMeasuredDacDelay();
|
||||||
|
size_t ceMeasuredDacDelayDims[2] ={1,1};
|
||||||
|
matvar_t* ceMeasuredDacDelayVar = Mat_VarCreate("CEMeasuredDACDelay",MAT_C_DOUBLE,MAT_T_DOUBLE,2,ceMeasuredDacDelayDims,&ceMeasuredDacDelay,0);
|
||||||
|
Mat_VarSetStructFieldByName(structVar, "CEMeasuredDACDelay", 0, ceMeasuredDacDelayVar);
|
||||||
//FilterBypass
|
//FilterBypass
|
||||||
double filterByPass = metaData.getFilterByPass();
|
double filterByPass = metaData.getFilterByPass();
|
||||||
size_t filterByPassDims[2] ={1,1};
|
size_t filterByPassDims[2] ={1,1};
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ SOURCES += \
|
|||||||
ShotList/ShotListPrivate.cpp \
|
ShotList/ShotListPrivate.cpp \
|
||||||
MatLab/MatlabCreatorPrivate.cpp \
|
MatLab/MatlabCreatorPrivate.cpp \
|
||||||
MatLab/MatlabCreatorVariableWindowPrivate.cpp \
|
MatLab/MatlabCreatorVariableWindowPrivate.cpp \
|
||||||
|
MatLab/MatlabCreatorConvertFp16Private.cpp \
|
||||||
Data/CEMeasuredData.cpp \
|
Data/CEMeasuredData.cpp \
|
||||||
Data/CEData.cpp \
|
Data/CEData.cpp \
|
||||||
Data/MetaData.cpp \
|
Data/MetaData.cpp \
|
||||||
@@ -86,6 +87,7 @@ HEADERS += \
|
|||||||
ShotList/ShotListPrivate.h \
|
ShotList/ShotListPrivate.h \
|
||||||
MatLab/MatlabCreatorPrivate.h \
|
MatLab/MatlabCreatorPrivate.h \
|
||||||
MatLab/MatlabCreatorVariableWindowPrivate.h \
|
MatLab/MatlabCreatorVariableWindowPrivate.h \
|
||||||
|
MatLab/MatlabCreatorConvertFp16Private.h \
|
||||||
Data/CEMeasuredData.h \
|
Data/CEMeasuredData.h \
|
||||||
Data/CEData.h \
|
Data/CEData.h \
|
||||||
Data/MetaData.h \
|
Data/MetaData.h \
|
||||||
|
|||||||
Reference in New Issue
Block a user