75 lines
1.8 KiB
Dart
75 lines
1.8 KiB
Dart
import 'dart:convert';
|
|
|
|
import '../io_tool/io_tool.dart';
|
|
import '../sm4Encipher/sm4.dart';
|
|
import '../io_reply.dart';
|
|
import '../io_sender.dart';
|
|
import '../io_type.dart';
|
|
import 'package:crypto/crypto.dart' as crypto;
|
|
|
|
/// 读取注册密钥
|
|
class SenderReadRegisterKeyCommand extends SenderProtocol {
|
|
SenderReadRegisterKeyCommand({
|
|
this.lockID,
|
|
this.token,
|
|
this.needAuthor,
|
|
this.publicKey,
|
|
this.privateKey,
|
|
}) : super(CommandType.readRegisterKey);
|
|
|
|
String? lockID;
|
|
|
|
List<int>? token;
|
|
int? needAuthor;
|
|
List<int>? publicKey;
|
|
List<int>? privateKey;
|
|
|
|
@override
|
|
String toString() {
|
|
return 'SenderReadRegisterKeyCommand{ lockID: $lockID, token: $token, '
|
|
'needAuthor: $needAuthor, publicKey: $publicKey, '
|
|
'privateKey: $privateKey}';
|
|
}
|
|
|
|
@override
|
|
List<int> messageDetail() {
|
|
List<int> data = <int>[];
|
|
List<int> ebcData = <int>[];
|
|
|
|
// 指令类型
|
|
final int type = commandType!.typeValue;
|
|
final double typeDouble = type / 256;
|
|
final int type1 = typeDouble.toInt();
|
|
final int type2 = type % 256;
|
|
data.add(type1);
|
|
data.add(type2);
|
|
|
|
// 锁id 40
|
|
final int lockIDLength = utf8.encode(lockID!).length;
|
|
data.addAll(utf8.encode(lockID!));
|
|
data = getFixedLengthList(data, 40 - lockIDLength);
|
|
|
|
if ((data.length % 16) != 0) {
|
|
final int add = 16 - data.length % 16;
|
|
for (int i = 0; i < add; i++) {
|
|
data.add(0);
|
|
}
|
|
}
|
|
|
|
printLog(data);
|
|
|
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
|
return ebcData;
|
|
}
|
|
}
|
|
|
|
class SenderReadRegisterKeyCommandReply extends Reply {
|
|
SenderReadRegisterKeyCommandReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
|
|
final int status = data[6];
|
|
errorWithStstus(status);
|
|
}
|
|
}
|