当前位置:网站首页>无线用的鉴权代码
无线用的鉴权代码
2022-07-17 00:34:00 【fitpolo】
给APP工程师看
randB: 97 1B 22 25 0F 22 E1 86 EA E5 D0 6B 38 C7 97 79
randA: B6 A9 D1 B3 93 6C 66 6D 8C E3 5A CA 65 65 B1 67
data1=32
B6 A9 D1 B3 93 6C 66 6D 8C E3 5A CA 65 65 B1 67 97 1B 22 25 0F 22 E1 86 EA E5 D0 6B 38 C7 97 79
0XB6,0XA9,0XD1,0XB3,0X93,0X6C,0X66,0X6D,0X8C,0XE3,0X5A,0XCA,0X65,0X65,0XB1,0X67,0X97,0X1B,0X22,0X25,0X0F,0X22,0XE1,0X86,0XEA ,0XE5 ,0XD0 ,0X6B ,0X38 ,0XC7 ,0X97 ,0X79
key1=20
90 B9 6E CA 29 7E F7 87 17 E6 6E 49 10 84 D3 F8 31 31 32 33
0x90,0xb9,0x6e,0xca,0x29,0x7e,0xf7,0x87,0x17,0xe6,0x6e,0x49,0x10,0x84,0xd3,0xf8,0X31,0X32,0X33,0X36
key2 = hmac_sha256(data1,key1);
算出来的值作为 key2
DD 7D 8A F5 FB CD 18 E3 D9 7D 1A 2A 58 E7 F9 35
1D C6 2A B0 8F 9E E9 79 34 37 07 7A C0 43 9E 52
key3 = hmac_sha256(data1,key2);
result
90 B2 70 0A 49 C4 F1 A3 45 6D E1 CC 0D 3D
B3 A1 E1 69 B6 8B 10 FA 95 13 93 DD 32 75 DC
80 70 87
鉴权的流程
测试代码
#include "stdio.h"
#include "stdint.h"
#include "user_encrypt.h"
#include "user_crc16.h"
static const uint8_t scale_factor[] = {
'9','8','5','6'};//秤端加权因子
static const uint8_t app_factor[] = {
'1','1','2','3'};//App端加权因子
uint8 rankA[] = {
0xB6, 0xA9 ,0xD1 ,0xB3 ,0x93 ,0x6C ,0x66 ,0x6D ,0x8C ,0xE3 ,0x5A ,0xCA ,0x65 ,0x65 ,0xB1 ,0x67};
uint8 rankB[] = {
0x97 ,0x1B ,0x22 ,0x25 ,0x0F ,0x22 ,0xE1 ,0x86 ,0xEA ,0xE5 ,0xD0 ,0x6B ,0x38 ,0xC7 ,0x97 ,0x79 };
//BD 12 10 B6 A9 D1 B3 93 6C 66 6D 8C E3 5A CA 65 65 B1 32 91
//BD 05 11 67 01 F3 22
//DB 12 30 97 1B 22 25 0F 22 E1 86 EA E5 D0 6B 38 C7 97 08 94
//DB 12 31 79 90 B2 70 0A 49 C4 F1 A3 45 6D E1 CC 0D 3D 62 FE
//DB 12 32 B3 A1 E1 69 B6 8B 10 FA 95 13 93 DD 32 75 DC BB 73
//DB 06 33 80 70 87 6C 7E
uint8_t test_token[32];
uint8_t test_crc16[32]={
0xBD ,0x12 ,0x10 ,0xB6 ,0xA9 ,0xD1 ,0xB3 ,0x93 ,0x6C ,0x66 ,0x6D ,0x8C ,0xE3 ,0x5A ,0xCA\
,0x65 ,0x65 ,0xB1};
uint16_t test_crc16_value;
#if 0
data是hash算法的原始数据,进行sha256后就是hash的数据,key和iv是aes算法的,in_data是aes的原始数据,out_data就是aes算法后的数据
static const uint8_t certificate[] = //预制鉴权秘钥
{
0x90, 0xB9, 0x6E, 0xCA, 0x29, 0x7E, 0xF7, 0x87,
0x17, 0xE6, 0x6E, 0x49, 0x10, 0x84, 0xD3, 0xF8
};
static const uint8_t scale_factor[] = {
'9','8','5','6'}; //秤端加权因子
static const uint8_t app_factor[] = {
'1','1','2','3'}; //App端加权因子
uint8 C1_Fac[16] = {
0xae, 0x39, 0x46, 0xd0, 0x61, 0xc9, 0x2e, 0x73, \
0x4f, 0x60, 0x64, 0xf5, 0x40, 0xeb, 0xb6, 0x92};
uint8 C2_Fac[16] = {
0xf2, 0xce, 0x6e, 0x2b, 0x4b, 0x23, 0x80, 0xed, \
0x96, 0x6b, 0xa2, 0x64, 0xea, 0x4b, 0x55, 0x12};」
#endif
#if 0
鉴权的流程
APP-------------------------Device
[APP->Device] [发送请求认证]
[Device->APP] [Device返回Rand A]
APP自己算出Rand B
预制鉴权秘钥 + App端加权因子 = Key
Rand A + Rand B = Value
TokenA=auth_make_token(Key,Value);//伪代码
[APP->Device] [接入合法认证 Rand B + TokenA]
[Device->APP] [Device返回TokenB]
#endif
int main(void)
{
uint8_t i=0;
for (i=0; i<16; i++)
{
userGlobalParameter.randA[i] = rankA[i];
userGlobalParameter.randB[i] = rankB[i];
}
auth_make_token((uint8_t*)scale_factor,test_token,0);
auth_make_token((uint8_t*)app_factor,test_token,0);//算出Token A
test_crc16_value = calcCrc16(test_crc16,0,18,0xffff);
printf("hello:0x%x\n",test_crc16_value);
test_crc16[0] = 0xDB;
test_crc16[1] = 0x03;
test_crc16[2] = 0x00;
test_crc16_value = calcCrc16(test_crc16,0,3,0xffff);
printf("hello:0x%x\n",test_crc16_value);
}
下载源码地址
边栏推荐
- Configure VLAN and use OSPF protocol for layer 3 switches
- ENSP static routing experiment
- Multi layer packet structure and TCP triple handshake
- 深入理解机器学习——类别不平衡学习(Imbalanced Learning):样本采样技术-[人工采样技术之ADASYN采样法]
- 【单片机仿真】(十)指令系统 — 算术运算指令 之 乘法指令、除法
- JDBC连接Mysql数据库
- Rsync - remote synchronization
- ncnn param文件及bin模型可视化解析
- 重写equals为什么要重写hashcode
- [MCU simulation] (VI) addressing mode - index addressing and relative addressing
猜你喜欢

What happens when you get stuck compiling and installing MySQL database in Linux system?

GraphQL初识

MySQL日志管理和完全备份增量备份与恢复

【PHP】tp6多表连接查询

RESNET learning notes

【MySQL】数据查询操作(select语句)

From the perspective of MySQL architecture, how does an SQL statement execute?
![mysqldump: [Warning] Using a password on the command line interface can be insecure.](/img/91/8b0d35f85bc0f46daac4e1e9bc9e34.png)
mysqldump: [Warning] Using a password on the command line interface can be insecure.

Summary of the most complete methods of string interception in Oracle

About XML file (VI) - the difference between JSON and XML file
随机推荐
[MCU simulation] (II) keil installation tutorial
【单片机仿真】(十五)指令系统位操作类指令 — 位运算指令、位条件转移指令
Mysql优化之索引
[MCU simulation] (XVIII) control transfer instructions - empty operation instructions
【单片机仿真】(十七)控制转移类指令 — 调用及返回指令
多项式插值拟合(二)
Mysql多表查询
LETV has more than 400 employees? Living a fairy life without a boss, the official responded
多项式插值拟合(三)
多项式插值拟合(一)
【MySQL】MHA高可用
2. Actual use of asynctool framework
Oracle获取最后一条,第一条数据(按时间获取第一条和最后一条数据)
Learning network foundation
Rip comprehensive experiment
SysTick定时器的基础学习以及手撕代码
Letv a plus de 400 employés? Le jour de l'immortel sans patron, les autorités ont répondu...
半年时间的思考
while 循环
mysqldump: [Warning] Using a password on the command line interface can be insecure.