GxDlms编译
title: GxDlms编译
date: 2019/12/5 13:36:37
toc: true
GxDlms编译
C++版本如果要编译动态库,项目>属性需要在
GXDLMSIp4Setup.h
加入#pragma comment(lib, "ws2_32.lib")//这是链接API相关连的Ws2_32.lib静态库
刚开始QT使用静态库的时候,提示一堆找不到,要注意默认qt这里使用的是x64,然后我们将vs编译的改成x64,再加入静态库就好了
qt加入库
qt编译的时候如果提示少
inet..
,加入步骤1中的头文件打包
windeployqt 工具命令:windeployqt hello.exe
一个小demo测试
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "./development/include/GXDLMSSecureClient.h"
#include <iostream>
using namespace std;
#include <QApplication>
#pragma comment(lib, "ws2_32.lib")
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::on_pushButton_clicked()
{ CGXCipher cipher("4D4D4D0000BC614E"); CGXByteBuffer SYS_TITLE;
SYS_TITLE.SetHexString("4D4D4D0000BC614E");
cipher.SetSystemTitle(SYS_TITLE); cipher.SetSecurity(DLMS_SECURITY_AUTHENTICATION_ENCRYPTION);
CGXByteBuffer EK;
EK.SetHexString("11111111111111111111111111111111");
cipher.SetBlockCipherKey(EK);
CGXByteBuffer AK;
AK.SetHexString("33333333333333333333333333333333");
cipher.SetAuthenticationKey(AK); cipher.SetFrameCounter(0); CGXByteBuffer plainText;
plainText.SetHexString("01000000065f1f040000181dffff"); CGXByteBuffer cryptedText; int cmd = 0x21;//DLMS_COMMAND_GENERAL_GLO_CIPHERING;
cryptedText.Clear();
cipher.Encrypt(cipher.GetSecurity(),
DLMS_COUNT_TYPE_TAG,
cipher.GetFrameCounter(),
cmd,
cipher.GetSystemTitle(),
cipher.GetBlockCipherKey(),
plainText,
cryptedText);
std::cout << "DLMS_COUNT_TYPE_TAG" << std::endl;
std::cout << cryptedText.ToHexString() << std::endl; cryptedText.Clear();
cipher.Encrypt(cipher.GetSecurity(),
DLMS_COUNT_TYPE_DATA,
cipher.GetFrameCounter(),
cmd,
cipher.GetSystemTitle(),
cipher.GetBlockCipherKey(),
plainText,
cryptedText);
cout << "DLMS_COUNT_TYPE_DATA" << endl;
cout << cryptedText.ToHexString() << endl; cryptedText.Clear();
cipher.Encrypt(cipher.GetSecurity(),
DLMS_COUNT_TYPE_PACKET,
cipher.GetFrameCounter(),
cmd,
cipher.GetSystemTitle(),
cipher.GetBlockCipherKey(),
plainText,
cryptedText);
cout << "DLMS_COUNT_TYPE_PACKET" << endl;
cout << cryptedText.ToHexString() << endl; ui->textEdit->setText(QString::fromStdString(cryptedText.ToHexString()));
}
- qt程序
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "./development/include/GXDLMSSecureClient.h"
#include <iostream>
using namespace std;
#include <QApplication>
#include <QDebug>
#include <QDataStream> #include <iostream>
#include <string>
#include <vector>
#include <algorithm> // 大写转换
#include <regex>
#pragma comment(lib, "ws2_32.lib")
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} class string_help
{
public:
string_help(); static bool IsHexNum(char c);
static void deleteAllMark(string &s, const string &mark); // 假定完美 hex形式的字符串形如 010203040506...FF 全是大写的并且
// 中间无任何分隔符
const static string demo_srting;
// 替换一次
static string replace_all(string& str, const string& old_value, const string& new_value);
// 迭代替换
static string replace_all_distinct(string& str, const string& old_value, const string& new_value); // hex数组转换为string
static string HexArrayToString(const vector<unsigned char >& data);
//转换一个string到完美string
static string HexStringFormat(const std::string& data=demo_srting);
// string转换为一个数组
static vector<unsigned char> StringToHexArray(const std::string& data=demo_srting);
}; const string string_help::demo_srting="500010203040506073031323334ff"; string string_help:: replace_all_distinct(string& str, const string& old_value, const string& new_value)
{
string::size_type pos=0;
while((pos=str.find(old_value,pos))!= string::npos)
{
str=str.replace(pos,old_value.length(),new_value);
if(new_value.length()>0)
{
pos+=new_value.length();
}
}
return str; } //替换2 循环替换,替换后的值也检查并替换 12212 替换12为21----->22211
string string_help::replace_all(string& str, const string& old_value, const string& new_value)
{
string::size_type pos=0;
while((pos=str.find(old_value))!= string::npos)
{
str=str.replace(str.find(old_value),old_value.length(),new_value);
}
return str;
} void string_help:: deleteAllMark(string &s, const string &mark)
{
size_t nSize = mark.size();
while(1)
{
size_t pos = s.find(mark); // 尤其是这里
if(pos == string::npos)
{
return;
} s.erase(pos, nSize);
}
} bool string_help::IsHexNum(char c)
{
if(c>='0' && c<='9') return true;
if(c>='a' && c<='f') return true;
if(c>='A' && c<='F') return true;
return false; } string string_help::HexStringFormat(const std::string& data)
{
vector<unsigned char >hex_array;
//1. 转换为大写
string format_string=data;
transform(data.begin(),data.end(),format_string.begin(),::toupper); //2. 去除0X
replace_all_distinct(format_string,"0X"," ");
replace(format_string.begin(),format_string.end(),',',' ');
replace(format_string.begin(),format_string.end(),',',' '); regex e("\\s+");
regex_token_iterator<string::iterator> i(format_string.begin(), format_string.end(), e, -1);
regex_token_iterator<string::iterator> end;
while (i != end)
{
//字串处理
string tmp_get=*i;
for(size_t i = 0; i < tmp_get.length(); )
{
if(IsHexNum(tmp_get[i]))
{
if(i+1<tmp_get.length() && IsHexNum(tmp_get[i+1]) )
{
string one=tmp_get.substr(i,2);
unsigned char value = static_cast<unsigned char>(std::stoi(one,0,16));
hex_array.push_back(value);
i++;
}
else
{
string one=tmp_get.substr(i,1);
unsigned char value = static_cast<unsigned char>(std::stoi(one,0,16));
hex_array.push_back(value);
}
//break;
}
i++;
}
i++;
}
return HexArrayToString(hex_array);
} vector<unsigned char> string_help::StringToHexArray(const std::string& src)
{
vector<unsigned char> ret;
if(src.size()<1)
{
ret.push_back(0x00);
return ret;
}
for (string::size_type i = 0; i < src.size()-1; i+=2)
{
string one=src.substr(i,2);
unsigned char value = static_cast<unsigned char>(std::stoi(one,0,16));
ret.push_back(value);
}
return ret;
} string string_help::HexArrayToString(const vector<unsigned char >& data)
{
const string hexme = "0123456789ABCDEF";
string ret="";
for(auto it:data)
{
ret.push_back(hexme[(it&0xF0) >>4]);
ret.push_back(hexme[it&0x0F]);
}
return ret;
} string format(QTextEdit * me,QString default_txt )
{
QString tmp=me->toPlainText(); if(tmp.size()<1)
tmp=default_txt; string good_string=string_help::HexStringFormat(tmp.toStdString());
QString good_qstring = QString::fromStdString(good_string);
me->setText(good_qstring);
return good_string;
} void MainWindow::on_pushButton_clicked()
{ //ui->sysText->setText(QString::fromStdString("123")); string s_systitle =format(ui->sysText,"4D4D4D0000BC614E");
string s_Ak =format(ui->AkText,"33333333333333333333333333333333");
string s_Ek =format(ui->EkText,"11111111111111111111111111111111");
string s_Ic =format(ui->IcEdit_8,"00");
string s_text =format(ui->plainText,"01000000065f1f040000181dffff");
string cmdme =format(ui->cmdme,"21"); CGXCipher cipher(s_systitle.c_str());
CGXByteBuffer SYS_TITLE;
SYS_TITLE.SetHexString(s_systitle.c_str());
CGXByteBuffer EK;
EK.SetHexString(s_Ek.c_str());
CGXByteBuffer AK;
AK.SetHexString(s_Ak.c_str());
CGXByteBuffer plainText;
plainText.SetHexString(s_text.c_str()); // SYS_TITLE.Clear();
// EK.Clear();
// AK.Clear();
// plainText.Clear();
// SYS_TITLE.SetHexString("4D4D4D0000BC614E");
// EK.SetHexString("11111111111111111111111111111111");
// AK.SetHexString("33333333333333333333333333333333");
// plainText.SetHexString("01000000065f1f040000181dffff"); int value_IC = QString::fromStdString(s_Ic).toInt(NULL, 16);
int value_cmd = QString::fromStdString(cmdme).toInt(NULL, 16); cipher.SetBlockCipherKey(EK);
cipher.SetAuthenticationKey(AK);
//cipher.SetFrameCounter(std::stol(s_Ic));
cipher.SetSystemTitle(SYS_TITLE);
cipher.SetFrameCounter(value_IC); std::cout << plainText.ToHexString() << std::endl;
cout << cipher.GetFrameCounter() <<endl;
std::cout << cipher.GetSystemTitle().ToHexString() << std::endl;
std::cout << cipher.GetBlockCipherKey().ToHexString() << std::endl;
std::cout << cipher.GetAuthenticationKey().ToHexString() << std::endl; CGXByteBuffer cryptedText; int cmd=value_cmd;
cipher.SetSecurity(DLMS_SECURITY_AUTHENTICATION_ENCRYPTION);
cryptedText.Clear();
cipher.Encrypt(cipher.GetSecurity(),
DLMS_COUNT_TYPE_PACKET,
cipher.GetFrameCounter(),
cmd,
cipher.GetSystemTitle(),
cipher.GetBlockCipherKey(),
plainText,
cryptedText);
std::cout << "DLMS_COUNT_TYPE_TAG" << std::endl;
std::cout << cryptedText.ToHexString() << std::endl; ui->enTextAll->setText(QString::fromStdString(cryptedText.ToHexString())); cryptedText.Clear();
cipher.SetSecurity(DLMS_SECURITY_ENCRYPTION);
cipher.Encrypt(cipher.GetSecurity(),
DLMS_COUNT_TYPE_DATA,
cipher.GetFrameCounter(),
cmd,
cipher.GetSystemTitle(),
cipher.GetBlockCipherKey(),
plainText,
cryptedText);
cout << "DLMS_COUNT_TYPE_DATA" << endl;
cout << cryptedText.ToHexString() << endl; ui->enTextData->setText(QString::fromStdString(cryptedText.ToHexString())); }<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1080</width>
<height>605</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTextEdit" name="plainText">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>631</width>
<height>91</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>690</x>
<y>370</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>加密</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>54</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>原文</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>140</y>
<width>121</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>密文(包含tag)</string>
</property>
</widget>
<widget class="QTextEdit" name="enTextAll">
<property name="geometry">
<rect>
<x>20</x>
<y>160</y>
<width>631</width>
<height>91</height>
</rect>
</property>
</widget>
<widget class="QTextEdit" name="enTextData">
<property name="geometry">
<rect>
<x>20</x>
<y>280</y>
<width>631</width>
<height>91</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>20</x>
<y>260</y>
<width>121</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>密文 数据域</string>
</property>
</widget>
<widget class="QTextEdit" name="enTextDataTag">
<property name="geometry">
<rect>
<x>20</x>
<y>410</y>
<width>631</width>
<height>91</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>670</x>
<y>10</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>sys-title</string>
</property>
</widget>
<widget class="QTextEdit" name="sysText">
<property name="geometry">
<rect>
<x>670</x>
<y>40</y>
<width>371</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>690</x>
<y>80</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Ak</string>
</property>
</widget>
<widget class="QTextEdit" name="AkText">
<property name="geometry">
<rect>
<x>670</x>
<y>100</y>
<width>371</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>690</x>
<y>140</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Ek</string>
</property>
</widget>
<widget class="QTextEdit" name="EkText">
<property name="geometry">
<rect>
<x>670</x>
<y>160</y>
<width>371</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>680</x>
<y>210</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>IC 帧序号</string>
</property>
</widget>
<widget class="QTextEdit" name="IcEdit_8">
<property name="geometry">
<rect>
<x>670</x>
<y>230</y>
<width>371</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>670</x>
<y>270</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>cmd</string>
</property>
</widget>
<widget class="QTextEdit" name="cmdme">
<property name="geometry">
<rect>
<x>670</x>
<y>290</y>
<width>371</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>790</x>
<y>370</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>解密包含tag</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>790</x>
<y>410</y>
<width>151</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>解密单纯数据,需要填写IC</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1080</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
GxDlms编译的更多相关文章
- TODO:macOS编译PHP7.1
TODO:macOS编译PHP7.1 本文主要介绍在macOS上编译PHP7.1,有兴趣的朋友可以去尝试一下. 1.下载PHP7.1源码,建议到PHP官网下载纯净到源码包php-7.1.0.tar.g ...
- Centos6.5下编译安装mysql 5.6
一:卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 rpm -e mysql //普通删除模式 rpm -e ...
- CENTOS 6.5 平台离线编译安装 PHP5.6.6
一.下载php源码包 http://cn2.php.net/get/php-5.6.6.tar.gz/from/this/mirror 二.编译 编译之前可能会缺少一些必要的依赖包,加载一个本地yum ...
- CENTOS 6.5 平台离线编译安装 Mysql5.6.22
一.下载源码包 http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.22.tar.gz 二.准备工作 卸载之前本机自带的MYSQL 安装 cmake,编 ...
- Android注解使用之注解编译android-apt如何切换到annotationProcessor
前言: 自从EventBus 3.x发布之后其通过注解预编译的方式解决了之前通过反射机制所引起的性能效率问题,其中注解预编译所采用的的就是android-apt的方式,不过最近Apt工具的作者宣布了不 ...
- Hawk 6. 编译和扩展开发
Hawk是开源项目,因此任何人都可以为其贡献代码.作者也非常欢迎使用者能够扩展出更有用的插件. 编译 编译需要Visual Stuido,版本建议使用2015, 2010及以上没有经过测试,但应该可以 ...
- android studio 使用 jni 编译 opencv 完整实例 之 图像边缘检测!从此在andrid中自由使用 图像匹配、识别、检测
目录: 1,过程感慨: 2,运行环境: 3,准备工作: 4,编译 .so 5,遇到的关键问题及其解决方法 6,实现效果截图. (原创:转载声明出处:http://www.cnblogs.com/lin ...
- 在Windows上编译和调试CoreCLR
生成CoreCLR - Windows篇 本文的唯一目的就是让你运行Hello World 运行环境 Window 7+ Visual studio 2015 确保C++ 工具已经被安装,默认是不安装 ...
- 【踩坑速记】二次依赖?android studio编译运行各种踩坑解决方案,杜绝弯路,总有你想要的~
这篇博客,只是把自己在开发中经常遇到的打包编译问题以及解决方案给大家稍微分享一下,不求吸睛,但求有用. 1.大家都知道我们常常会遇到dex超出方法数的问题,所以很多人都会采用android.suppo ...
随机推荐
- BZOJ 4864: [BeiJing 2017 Wc]神秘物质 (块状链表/平衡树 )
这就是一道数据结构裸题啊,最大极差就是区间最大值减最小值,最小极差就是相邻两个数差的最小值.然后平衡树splay/treap或者块状链表维护就行了. 第一次自己写块状链表,蛮好写,就是长..然后就BZ ...
- mysql 数据库练习题
前面学习了MySQL的语句的基本用法,这里就开始做一些MySQL练习,这套题目一共45题,属于比较简单的,初学先试着做这个. 参考链接:https://www.cnblogs.com/SJP666/p ...
- pyinstaller打包好的.exe程序在别的电脑上运行出错
打开.exe提示: Failed to execute script... 查看命令行错误提示为: 总的来说呢,就是有的版本pyqt5库对系统变量的加载存在bug,具体原因只有官方才能解释了,咱也没法 ...
- 002_linuxC++_.h和.c文件
(一)程序修改001_linuxC++之_类的引入 (二)修改成为.h和.c文件 #include <stdio.h> #include "person.h" int ...
- 基础数据类型-字符串str
什么是字符串? 单引号,双引号,三引号包裹的文本 在我们的代码中换行区别 单/双引号:‘a’\ 'b' 三引号:"""a b""" 索引 s ...
- 把Cstring类型的字符串转化为char* 字符串;
int char_leng; Cstring str="abcd"; char_leng=str.GetLength();//获取字符串长度 char *str_temp=(cha ...
- CF1140F Extending Set of Points 【按时间分治,并查集】
题目链接:洛谷 首先我们考虑没有撤回操作的情况,就是将每一行和每一列看做一个点(代表行的称为白点,代表列的称为黑点),每个点$(x,y)$看做一条边. Extend操作实际上就是$x_1$行与$y_1 ...
- bit,byte,word,bps,Bps,比特,字节,字, 一图看懂
- Sketch教程
去年夏天开始用Sketch,觉得它放Dock里闪亮亮的很好看,当时笑称是男盆友送我的第一颗小钻石噗哈哈.所以那段时间几乎刷遍了所有关于 Sketch 的网站.文章.教程,之后又在自学设计,因为想和更多 ...
- linux C file format analysis
c语言文件格式 source file file.c C source, ASCII text pretreatment 预处理文件 file.i C source, ASCII text assem ...