zoukankan      html  css  js  c++  java
  • SecurityAccess 之 KeyGenDll_GenerateKeyEx

      在使用诊断功能时,会涉及SecurityAccess,KeyGenDll_GenerateKeyEx是一种根据seed计算SecurityAccess key的方法,在Vector CANoe提供的Sample Configurations中就有Demo。默认安装位置: C:UsersPublicDocumentsVectorCANoeSample Configurations 11.0.42CANDiagnosticsUDSSystemSecurityAccessSourcesKeyGenDll_GenerateKeyEx

      每个项目都具有独特性,这里根据我的项目实际情况,分享一下KeyGenDll_GenerateKeyEx使用方法:

    代码:

    // KeyGeneration.cpp : Defines the entry point for the DLL application.
    //
    
    #include <windows.h>
    #include "KeyGenAlgoInterfaceEx.h"
    
    
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
                         )
    {
        return TRUE;
    }
    
    
    
    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] */
          )
    {
        //Copy seed from parameter to a integer
        //Note:The byte order in the seed array is equal to the byte order in the bus message
        unsigned int seed = 0;
        unsigned int key = 0;
        
        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 )
        {
            //for security access with Services 0x27 01 -> 0x27 02
            printf("iSecurityLevel is %02X",iSecurityLevel);
            
            //Security algorithm has been deleted
            key = seed;
            
            printf("key is %02X",key);
        }
        else
        {
            key = 0xFFFFFFFF;
            printf("- - - Error ! - - -");
        }
        //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;
        printf("ioKeyArray is %02X",ioKeyArray);
          
        oSize=iSeedArraySize;
        
      return KGRE_Ok;
    }
  • 相关阅读:
    mysql 8 查询报错(sql_mode=only_full_group_by)
    docker安装mysql8版本后 客户端连接出现client does not support authentication...
    docker常用命令
    查看tomcat日志相关Linux命令
    java项目部署到linux服务器涉及的命令
    ehcache与redis对比
    JS中调用BigDecimal处理金额
    thymeleaf模板 th:href 踩坑
    汇总一些绝对有价值的解决方案,边学习边收集
    spring注解总结,spring注解大全
  • 原文地址:https://www.cnblogs.com/zinthewind/p/14173939.html
Copyright © 2011-2022 走看看