110 lines
3.0 KiB
Dart
110 lines
3.0 KiB
Dart
|
||
import 'dart:convert';
|
||
|
||
import '../../tools/storage.dart';
|
||
import '../io_tool/io_tool.dart';
|
||
import 'io_reply.dart';
|
||
import 'io_sender.dart';
|
||
import 'io_type.dart';
|
||
|
||
import 'package:crypto/crypto.dart' as a;
|
||
|
||
class GetPrivateKeyCommand extends SenderProtocol {
|
||
|
||
String? lockID;
|
||
String? keyID; // 钥匙ID
|
||
String? authUserID; // 钥匙授权人ID
|
||
int? nowTime;
|
||
int? needAuthor;
|
||
GetPrivateKeyCommand({
|
||
this.lockID,
|
||
this.keyID,
|
||
this.authUserID,
|
||
this.nowTime,
|
||
this.needAuthor,
|
||
}) : super(CommandType.getLockPrivateKey);
|
||
|
||
@override
|
||
List<int> messageDetail() {
|
||
List<int> data = [];
|
||
List<int> ebcData = [];
|
||
print("lockID:${lockID!} lockID.utf8.encode${utf8.encode(lockID!)}");
|
||
|
||
// 锁id
|
||
int lockIDLength = utf8.encode(lockID!).length;
|
||
data.addAll(utf8.encode(lockID!));
|
||
data = getFixedLengthList(data, 40 - lockIDLength);
|
||
|
||
//KeyID 40
|
||
int keyIDLength = utf8.encode(keyID!).length;
|
||
data.addAll(utf8.encode(keyID!));
|
||
data = getFixedLengthList(data, 40 - keyIDLength);
|
||
|
||
//authUserID 40
|
||
int authUserIDLength = utf8.encode(authUserID!).length;
|
||
data.addAll(utf8.encode(authUserID!));
|
||
data = getFixedLengthList(data, 20 - authUserIDLength);
|
||
|
||
//NowTime 4
|
||
// DateTime now = DateTime.now();
|
||
// int timestamp = now.millisecondsSinceEpoch;
|
||
var d1 = 0x11223344;
|
||
data.add((d1 & 0xff000000) >> 24);
|
||
data.add((d1 & 0xff0000) >> 16);
|
||
data.add((d1 & 0xff00) >> 8);
|
||
data.add((d1 & 0xff));
|
||
|
||
if(needAuthor == 0){
|
||
data.add(0);
|
||
}else{
|
||
List<int> authCodeData = [];
|
||
|
||
//KeyID
|
||
authCodeData.addAll(utf8.encode(keyID!));
|
||
|
||
//authUserID
|
||
authCodeData.addAll(utf8.encode(authUserID!));
|
||
|
||
//NowTime 4
|
||
// DateTime now = DateTime.now();
|
||
// int timestamp = now.millisecondsSinceEpoch;
|
||
var d1 = 0x11223344;
|
||
authCodeData.add((d1 & 0xff000000) >> 24);
|
||
authCodeData.add((d1 & 0xff0000) >> 16);
|
||
authCodeData.add((d1 & 0xff00) >> 8);
|
||
authCodeData.add((d1 & 0xff));
|
||
|
||
var pubKey = Storage.getData("bluePublicKey");
|
||
List<int> pubKeyData = utf8.encode(pubKey.toString());
|
||
authCodeData.addAll(pubKeyData);
|
||
|
||
// var stringEncoded = md5Crypto(authCodeData);
|
||
// data.add(stringEncoded.length);
|
||
|
||
var authCode = a.md5.convert(authCodeData);
|
||
print("authCodeData:$authCodeData authCode:$authCode");
|
||
|
||
data.add(authCode.bytes.length);
|
||
data.addAll(authCode.bytes);
|
||
|
||
print("authCode:$authCode authCode.bytes.length:${authCode.bytes.length} data:$data ebcData$ebcData");
|
||
}
|
||
ebcData = getDNSAPIStr(data, "TMH_c3570480da8d").bytes;
|
||
return ebcData;
|
||
}
|
||
}
|
||
|
||
class GetPrivateKeyReply extends Reply {
|
||
GetPrivateKeyReply.parseData(CommandType commandType, List<int> dataDetail)
|
||
: super.parseData(commandType, dataDetail) {
|
||
print('获取私钥');
|
||
int index = 0;
|
||
// while(index < endIndex){
|
||
// commandKey = byteUInt8(dataDetail, index);
|
||
// index += offset_1;
|
||
// switch(commandKey){
|
||
//
|
||
// }
|
||
// }
|
||
}
|
||
} |