当前位置:网站首页>无线用的鉴权代码
无线用的鉴权代码
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);
}
下载源码地址
边栏推荐
猜你喜欢
随机推荐
ncnn paramdict&modelbin
Advanced usage of the responsibility chain pattern
Introduction to wangeditor (entry level)
1. Introduction, analysis and implementation of asynctool framework
Que se passe - t - il lorsque vous compilez et installez une base de données MySQL bloquée dans un système Linux?
【MySQL】数据查询操作(select语句)
Fiddler抓包
C language foundation day4 array
【回归预测】基于粒子滤波实现锂离子电池寿命预测附matlab代码
[MCU simulation] (XIX) introduction to assembly, assembly instructions, pseudo instructions
DHCP service
mysqldump: [Warning] Using a password on the command line interface can be insecure.
05_服务调用Ribbon
【单片机仿真】(二十一)DB(Define Byte)— 定义字节
樂視還有400多比特員工?過著沒有老板的神仙日子 官方出來回應了...
当你在Linux系统中编译安装MySQL数据库卡住了怎么办?
Built in keyboard continuous 444
Summary of the most complete methods of string interception in Oracle
ncnn DataReader&Extractor&blob
仿射变换实现









