lazarus在arm64/龙芯等linux电脑使用域天加密锁要注意的事项:
1、使用域天官方的接口单元时加密锁的so文件必须拷贝到/usr/lib/这个目录。
2、普通用户如果调用加密锁so出错或失败,需要进行以下操作:
1、使用域天官方的接口单元时加密锁的so文件必须拷贝到/usr/lib/这个目录。
2、普通用户如果调用加密锁so出错或失败,需要进行以下操作:
建一个规则文件放
/etc/udev/rules.d
文件内容如下:
SUBSYSTEM=="input", GROUP="input", MODE="0666" SUBSYSTEM=="usb", ATTRS{idVendor}=="3689", ATTRS{idProduct}=="8762", MODE:="666", GROUP="plugdev" KERNEL=="hidraw*", ATTRS{idVendor}=="3689", ATTRS{idProduct}=="8762", MODE="0666", GROUP="plugdev"
将以上的内容保存为一个新的文件例如:
/etc/udev/rules.d/51-blink1.rules
然后拨出设备,在终端运行以下命令就可以了:
sudo udevadm control --reload-rules
注意,加密狗设备的PID及VID一定要是16进制及小写。
===========================================
将加密锁的so放/usr/lib文件夹不方便,可以用以下单元替换域天官方的单元,只需将加密锁的so和应用放在同一目录就可以。
{*******************************************************} { } { Borland Delphi Supplemental Components } { ZLIB Data Compression Interface Unit } { } { Copyright (c) 1997,99 Inprise Corporation } { } {*******************************************************} {$mode delphi} //{$linklib /home/lb/fpcupdeluxe/YT88/lazarus_demo/libPsyunew3_arm8.so} unit SoftKeyYT88_fpc; interface uses SysUtils, {$ifdef windows} Windows, {$endif} Classes,StrUtils; type ////////////////////////////////////////////////////////////////////////////////////////////////////////////// //查找加密锁 TFindPort=function(Start: integer; OutPath: PChar):integer;stdcall; //从加密锁中读取一个字节,一般不使用 TYRead=function(var Out_EPROM: byte; Address: smallint; hkey,lkey,InPath: PAnsiChar):integer;stdcall; //从加密锁中读字符串 TYReadString=function(OurStr: PAnsiChar; Address: SmallInt; Len: Integer; HKey, LKey: PAnsiChar; InPath: PAnsiChar):integer;stdcall; //写一个字节到加密锁中,一般不使用 TYWrite=function(InData: byte; Address: smallint;hkey,lkey, InPath: PAnsiChar):integer;stdcall; //写字符串到加密锁中 TYWriteString=function(InStr: PAnsiChar; Address: SmallInt; HKey, LKey: PAnsiChar; InPath: PAnsiChar):integer;stdcall; //查找指定的加密锁(使用普通算法一) TFindPort_2=function(Start: integer; In_Data: DWord; Verf_Data: DWord; OutPath: PAnsiChar): integer;stdcall; //获到锁的版本 TNT_GetIDVersion=function(var AVersion: integer; InPath: PAnsiChar): integer;stdcall; //获到锁的扩展版本 TNT_GetVersionEx=function(var AVersion: integer; InPath: PAnsiChar): integer;stdcall; //获取锁的ID TGetID=function(var ID_1, ID_2: DWord; InPath: PAnsiChar): integer;stdcall; //算法函数 TsWriteEx=function(InData: DWord;var OutData:DWORD; InPath: PAnsiChar): integer;stdcall; TsWrite_2Ex=function(InData: DWord;var OutData:DWORD; InPath: PAnsiChar): integer;stdcall; TsWrite=function(InData: DWord; InPath: PAnsiChar): integer;stdcall; TsWrite_2=function(InData: DWord; InPath: PAnsiChar): integer;stdcall; TsRead=function(var Out_Data: DWord; InPath: PChar): integer; stdcall; //从加密锁中读取一批字节 TYReadEx=function(OutData: PByte; Address: SmallInt; Len: SmallInt; HKey, LKey: PAnsiChar; InPath: PAnsiChar): Integer;stdcall; //写一批字节到加密锁中 TYWriteEx=function(InData: PByte; Address: SmallInt; Len: SmallInt; HKey, LKey: PAnsiChar; InPath: PAnsiChar): Integer;stdcall; //设置读密码 TSetReadPassword=function(HKey, LKey: PAnsiChar; New_HKey, New_LKey: PAnsiChar; InPath: PAnsiChar): Integer;stdcall; //设置写密码 TSetWritePassword=function(HKey, LKey: PAnsiChar; New_HKey, New_LKey: PAnsiChar; InPath: PAnsiChar): Integer;stdcall; //设置增强算法密钥一 TSetCal_2=function(Key,InPath:PAnsiChar): Integer;stdcall; //使用增强算法一对字符串进行加密 TEncString=function(InString,OutString,Path:PAnsiChar): Integer;stdcall; //使用增强算法一对二进制数据进行加密 TCal=function(InBuf,OutBuf:PBYTE;Path:PAnsiChar): Integer;stdcall; //设置增强算法密钥二 TSetCal_New=function(Key,InPath:PAnsiChar): Integer;stdcall; //使用增强算法二对字符串进行加密 TEncString_New=function(InString,OutString,Path:PAnsiChar): Integer;stdcall; //使用增强算法二对二进制数据进行加密 TCal_New=function(InBuf,OutBuf:PBYTE;Path:PAnsiChar): Integer;stdcall; //使用增强算法对字符串进行解密(使用软件) TDecString=procedure(InString,OutString,Key:PAnsiChar);stdcall; //使用增强算法对二进制数据进行加密(使用软件) TDecBySoft=procedure(aData, aKey:PBYTE);stdcall; TEncBySoft=procedure(aData, aKey:PBYTE);stdcall; //字符串及二进制数据的转换 THexStringToByteArray=procedure(InString:PAnsiChar;out_data:PBYTE);stdcall; TByteArrayToHexString=procedure(in_data:PBYTE;OutString:PAnsiChar;len:integer);stdcall; //初始化锁函数 TReSet=function(Path:PAnsiChar): Integer;stdcall; //设置锁的ID TSetID=function(Seed,InPath:PAnsiChar): Integer;stdcall; //设置锁的普通算法密钥 TSetCal=function(W_HKey,W_LKey,new_HKey,new_LKey,InPath:PAnsiChar): Integer;stdcall; //返回锁的出厂编码 TGetProduceDate=function(OutPDdate,InPath:PAnsiChar): Integer;stdcall; //以下函数只限于带U盘的锁 //设置是否显示U盘部分盘符,真为显示,否为不显示 TSetHidOnly=function( IsHidOnly:boolean;InPath:pansichar): Integer;stdcall; //设置U盘部分为只读状态, TSetUReadOnly=function( nPath:pansichar): Integer;stdcall; //返回U盘部分是否为只读状态,真为只读 TIsUReadOnly=function(var IsReadOnly :boolean;InPath:pansichar): Integer;stdcall; //查找指定的加密锁(使得普通算法二),返回的是U盘的路径,即U盘的盘符,通过这个路径也可以直接操作锁 TFindU_3=function( Start: integer; In_Data: DWord; Verf_Data: DWord; OutPath: pansichar): Integer;stdcall; //查找指定的加密锁(使得普通算法一),返回的是U盘的路径,即U盘的盘符,通过这个路径也可以直接操作锁 TFindU_2=function( Start: integer; In_Data: DWord; Verf_Data: DWord; OutPath: pansichar): Integer;stdcall; //查找加密锁,返回的是U盘的路径,即U盘的盘符,通过这个路径也可以直接操作锁 TFindU=function( Start: integer; OutPath: pansichar): Integer;stdcall; //SM2算法函数 //生成SM2密钥对 TYT_GenKeyPair=function(PriKey , PubKeyX ,PubKeyY , InPath: PAnsiChar): integer; stdcall; //设置SM2密钥对到锁中 TSet_SM2_KeyPair=function(PriKey, PubKeyX , PubKeyY , Sm2UserName, InPath: PAnsiChar): integer; stdcall; //从锁中取得设置在锁中的公钥 TGet_SM2_PubKey=function(PubKeyX, PubKeyY , Sm2UserName , InPath: PAnsiChar): integer; stdcall; //使用锁中的公钥对字符串进行加密 TSM2_EncString=function( InString , outstring, InPath : PAnsiChar): integer; stdcall; //使用锁中的私钥对字符串进行解密 TSM2_DecString=function( InString , outstring , pin, InPath: PAnsiChar): integer; stdcall; //使用锁中的公钥对二进制数组进行加密 TSM2_EncBuf=function( InBuf , OutBuf:PByte; inlen :Integer; InPath: PAnsiChar): integer;stdcall; //使用锁中的私钥对二进制数组进行解密 TSM2_DecBuf=function(InBuf , OutBuf:PByte; inlen : Integer; pin , InPath: PAnsiChar): integer;stdcall; //设置PIN码 TYtSetPin=function( old_pin , new_pin, InPath: PAnsiChar): integer; stdcall; //使用锁内的私钥对数据进行签名 TYtSign=function( msg , OutSign, pin , InPath: PAnsiChar): integer; stdcall; //使用公钥对签名进行检验 TYtVerfiy=function(id , msg , kx , ky , VerfiySign: PAnsiChar; IsVailSign : PBoolean; InPath: PAnsiChar): integer;stdcall; //获取锁的硬件芯片唯一ID TGetChipID=function( OutChipID , InPath: PAnsiChar): integer;stdcall; //设置为禁止初始化 TSetDisableFlag=function(IsDisableReSet:boolean;HKey,LKey,InPath: PAnsiChar): integer;stdcall; //返回编码具体含义 function SnToProduceDate( InSn:string):string; var lib:TLibHandle; FindPort:TFindPort; YRead:TYRead; YReadString:TYReadString; YWrite:TYWrite; YWriteString:TYWriteString; FindPort_2:TFindPort_2; NT_GetIDVersion:TNT_GetIDVersion; NT_GetVersionEx:TNT_GetVersionEx; GetID:TGetID; //算法函数 sWriteEx:TsWriteEx; sWrite_2Ex:TsWrite_2Ex; sWrite:TsWrite; sWrite_2:TsWrite_2; sRead:TsRead; YReadEx:TYReadEx; YWriteEx:TYWriteEx; SetReadPassword:TSetReadPassword; SetWritePassword:TSetWritePassword; SetCal_2:TSetCal_2; EncString:TEncString; Cal:TCal; SetCal_New:TSetCal_New; EncString_New:TEncString_New; Cal_New:TCal_New; DecString:TDecString; DecBySoft:TDecBySoft; EncBySoft:TEncBySoft; HexStringToByteArray:THexStringToByteArray; ByteArrayToHexString:TByteArrayToHexString; ReSet:TReSet; SetID:TSetID; SetCal:TSetCal; GetProduceDate:TGetProduceDate; SetHidOnly:TSetHidOnly; SetUReadOnly:TSetUReadOnly; IsUReadOnly:TIsUReadOnly; FindU_3:TFindU_3; FindU_2:TFindU_2; FindU:TFindU; YT_GenKeyPair:TYT_GenKeyPair; Set_SM2_KeyPair:TSet_SM2_KeyPair; Get_SM2_PubKey:TGet_SM2_PubKey; SM2_EncString:TSM2_EncString; SM2_DecString:TSM2_DecString; SM2_EncBuf:TSM2_EncBuf; SM2_DecBuf:TSM2_DecBuf; YtSetPin:TYtSetPin; YtSign:TYtSign; YtVerfiy:TYtVerfiy; GetChipID:TGetChipID; SetDisableFlag:TSetDisableFlag; implementation function SnToProduceDate( InSn:string):string; var OutString:string; Function HexToInt(Hex : String) : Integer; Const HexSymbols : String = '0123456789ABCDEF'; Var I,J : Integer; Begin Hex := UpperCase(Hex); Result := 0; J := Length(Hex); For I := 1 to J do Result := Result+((Pos(Hex[J-I+1],HexSymbols)-1) shl ((I-1)*4)); End; begin OutString := inttoStr(2000 + HexToInt(PAnsiChar(MidStr(InSn, 1, 2))))+ '年'; OutString := OutString + inttoStr(HexToInt(PAnsiChar(MidStr(InSn, 3, 2)))) + '月'; OutString := OutString + inttoStr(HexToInt(PAnsiChar(MidStr(InSn, 5, 2)))) + '日'; OutString := OutString + inttoStr(HexToInt(PAnsiChar(MidStr(InSn, 7, 2)))) + '时'; OutString := OutString + inttoStr(HexToInt(PAnsiChar(MidStr(InSn, 9, 2)))) + '分'; OutString := OutString + inttoStr(HexToInt(PAnsiChar(MidStr(InSn, 11, 2)))) + '秒--'; OutString := OutString + '序号:' + inttoStr(HexToInt(PAnsiChar(MidStr(InSn, 13, 4)))); result:=OutString; end; Initialization {$if defined(cpuloongarch64)} lib:=LoadLibrary(ExtractFilePath(ParamStr(0))+'libPsyunew3_mips_3a.so'); {$endif} {$if defined(cpuaarch64)} lib:=LoadLibrary(ExtractFilePath(ParamStr(0))+'libPsyunew3_arm8.so'); {$endif} FindPort:=TFindPort(GetProcAddress(lib,'FindPort')); YRead:=TYRead(GetProcAddress(lib,'YRead')); YReadString:=TYReadString(GetProcAddress(lib,'YReadString')); YWrite:=TYWrite(GetProcAddress(lib,'YWrite')); YWriteString:=TYWriteString(GetProcAddress(lib,'YWriteString')); FindPort_2:=TFindPort_2(GetProcAddress(lib,'FindPort_2')); NT_GetIDVersion:=TNT_GetIDVersion(GetProcAddress(lib,'NT_GetIDVersion')); NT_GetVersionEx:=TNT_GetVersionEx(GetProcAddress(lib,'NT_GetVersionEx')); GetID:=TGetID(GetProcAddress(lib,'GetID')); sWriteEx:=TsWriteEx(GetProcAddress(lib,'sWriteEx')); sWrite_2Ex:=TsWrite_2Ex(GetProcAddress(lib,'sWrite_2Ex')); sWrite:=TsWrite(GetProcAddress(lib,'sWrite')); sWrite_2:=TsWrite_2(GetProcAddress(lib,'sWrite_2')); sRead:=TsRead(GetProcAddress(lib,'sRead')); YReadEx:=TYReadEx(GetProcAddress(lib,'YReadEx')); YWriteEx:=TYWriteEx(GetProcAddress(lib,'YWriteEx')); SetReadPassword:=TSetReadPassword(GetProcAddress(lib,'SetReadPassword')); SetWritePassword:=TSetWritePassword(GetProcAddress(lib,'SetWritePassword')); SetCal_2:=TSetCal_2(GetProcAddress(lib,'SetCal_2')); EncString:=TEncString(GetProcAddress(lib,'EncString')); Cal:=TCal(GetProcAddress(lib,'Cal')); SetCal_New:=TSetCal_New(GetProcAddress(lib,'SetCal_New')); EncString_New:=TEncString_New(GetProcAddress(lib,'EncString_New')); Cal_New:=TCal_New(GetProcAddress(lib,'Cal_New')); DecString:=TDecString(GetProcAddress(lib,'DecString')); DecBySoft:=TDecBySoft(GetProcAddress(lib,'DecBySoft')); EncBySoft:=TEncBySoft(GetProcAddress(lib,'EncBySoft')); HexStringToByteArray:=THexStringToByteArray(GetProcAddress(lib,'HexStringToByteArray')); ByteArrayToHexString:=TByteArrayToHexString(GetProcAddress(lib,'ByteArrayToHexString')); ReSet:=TReSet(GetProcAddress(lib,'ReSet')); SetID:=TSetID(GetProcAddress(lib,'SetID')); SetCal:=TSetCal(GetProcAddress(lib,'SetCal')); GetProduceDate:=TGetProduceDate(GetProcAddress(lib,'GetProduceDate')); SetHidOnly:=TSetHidOnly(GetProcAddress(lib,'SetHidOnly')); SetUReadOnly:=TSetUReadOnly(GetProcAddress(lib,'SetUReadOnly')); IsUReadOnly:=TIsUReadOnly(GetProcAddress(lib,'IsUReadOnly')); FindU_3:=TFindU_3(GetProcAddress(lib,'FindU_3')); FindU_2:=TFindU_2(GetProcAddress(lib,'FindU_2')); FindU:=TFindU(GetProcAddress(lib,'FindU')); YT_GenKeyPair:=TYT_GenKeyPair(GetProcAddress(lib,'YT_GenKeyPair')); Set_SM2_KeyPair:=TSet_SM2_KeyPair(GetProcAddress(lib,'Set_SM2_KeyPair')); Get_SM2_PubKey:=TGet_SM2_PubKey(GetProcAddress(lib,'Get_SM2_PubKey')); SM2_EncString:=TSM2_EncString(GetProcAddress(lib,'SM2_EncString')); SM2_DecString:=TSM2_DecString(GetProcAddress(lib,'SM2_DecString')); SM2_EncBuf:=TSM2_EncBuf(GetProcAddress(lib,'SM2_EncBuf')); SM2_DecBuf:=TSM2_DecBuf(GetProcAddress(lib,'SM2_DecBuf')); YtSetPin:=TYtSetPin(GetProcAddress(lib,'YtSetPin')); YtSign:=TYtSign(GetProcAddress(lib,'YtSign')); YtVerfiy:=TYtVerfiy(GetProcAddress(lib,'YtVerfiy')); GetChipID:=TGetChipID(GetProcAddress(lib,'GetChipID')); SetDisableFlag:=TSetDisableFlag(GetProcAddress(lib,'SetDisableFlag')); end.