DLL制作步骤
-
Step1
制作该文件,可直接用Vector自带模板【KeyGenDll_GenerateKeyEx】,在该Demo下进行修改&整合。
Demo路径如下:
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 11.0.55\CAN\Diagnostics\UDSSystem\SecurityAccess\Sources
-
Step2
拷贝该Demo至文件夹,使用Visual Studio打开工工程模板
-
Step3
修改算法
KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
const unsigned char* iSeedArray, /* Array for the seed [in] */
unsigned int iSeedArraySize, /* Length of the array for the seed [in] */
const unsigned int iSecurityLevel, /* Security level [in] */
const char* iVariant, /* Name of the active variant [in] */
unsigned char* ioKeyArray, /* Array for the key [in, out] */
unsigned int iKeyArraySize, /* Maximum length of the array for the key [in] */
unsigned int& oSize /* Length of the key [out] */
)
{
unsigned int seed = 0;
unsigned int key = 0;
unsigned long secret_keyAPP = 0x11111111;
unsigned long secret_keyBoot = 0x22222222;
seed = seed | (iSeedArray[3] << 0);
seed = seed | (iSeedArray[2] << 8);
seed = seed | (iSeedArray[1] << 16);
seed = seed | (iSeedArray[0] << 24);
//begin calculate key form seed
if (0x01 == iSecurityLevel)
{
Initgenerate_tables();
key = SAcrypt_Data(seed, secret_keyBoot);
}
else if(0x03 == iSecurityLevel){
Initgenerate_tables();
key = SAcrypt_Data(seed, secret_keyAPP);
}
//end calculate key form seed
//copy key to the output buffer
//Note:The first byte of the key array will be the first key byte of the bus message
ioKeyArray[3] = key & 0xff;
ioKeyArray[2] = (key >> 8) & 0xff;
ioKeyArray[1] = (key >> 16) & 0xff;
ioKeyArray[0] = (key >> 24) & 0xff;
oSize = iSeedArraySize;
return KGRE_Ok;
}
- Step4
生成DLL文件SeednKey.dll
导航栏点击【生成—>生成解决方案】,编译成功后,生成的DLL文件在Debug文件夹中
配置文件&调用
- Step1
在诊断台中配置DLL文件,步骤如下:
- Step2
诊断台发送