public void InitContext() { this.hexConverter = new HexConverter(); this.byteWorker = new ByteWorker(); //KMS參數設定 kms_context_param_t ctx_param = new kms_context_param_t(); ctx_param.app_name = "kms2Test"; ctx_param.kms_server = //@"http://10.27.68.163:8080/eGATEsKMS/interface"; @"http://127.0.0.1:8081/eGATEsKMS/interface"; ctx_param.ssl = 0; ctx_param.debug = 1; ctx_param.timeout = 30; ctx_param.connect_timeout = 10; ctx_param.auth_with_cipher = 1; //DLL要在X64下跑,所以編譯的設定都改成x64和容許UnSafe程式碼(因DLL是C++寫的),測試設定的預設處理器架構也要改x64 this.esKmsApi = EsKmsApi.GetInstance(ctx_param); }
public static EsKmsApi GetInstance(kms_context_param_t ctx_param) { uint r = 0; uint out_ctx = 0; Debug.WriteLine("Begin GetInstance ..."); //load eskmsApi.dll try { r = kms_context_create(ref out_ctx, ref ctx_param); if (r != 0) { Debug.WriteLine(String.Format("eskmsapi error: 0x{0:X8}", r)); throw new Exception(String.Format("eskmsapi error: 0x{0:X8}", r)); } } catch (Exception ex) { var qq = ex; } Debug.WriteLine(String.Format("End GetInstance:[{0:X8}]", r)); EsKmsApi kmsapi = new EsKmsApi(); kmsapi.ctx = out_ctx; return kmsapi; }
public static extern uint kms_context_create(ref uint ctx, ref kms_context_param_t ctx_param);
public EsKmsApi(string kmsServer, string appCode, string authCode, string appName) { //create EsKmsApi.Dll need Infomation and setting kms_context_param_t ctx_param = new kms_context_param_t(); ctx_param.app_name = appName; ctx_param.kms_server = kmsServer; ctx_param.ssl = 0; ctx_param.debug = 0; ctx_param.timeout = 30; ctx_param.connect_timeout = 10; ctx_param.auth_with_cipher = 1; // uint r = 0; uint out_ctx = 0;//Dll return code r = kms_context_create(ref out_ctx, ref ctx_param); if (r != KMS_NO_ERROR) { string errStr = String.Format("Eskmsapi init error: 0x{0:X8}", r); Debug.WriteLine(errStr); throw new Exception(errStr); } this.ctx = out_ctx; Debug.WriteLine(String.Format("Eskmsapi init ok: 0x{0:X8}", this.ctx)); this.appCode = appCode; this.authCode = authCode; }