public string Security_DLL(byte[] DataReceive, string pathname) { byte[] key = new byte[4]; byte[] seed = new byte[4]; string strDatebyte = ""; for (int i = 0; i < 4; i++) { seed[i] = DataReceive[6 + i]; } if (pathname != "") { Dll dllinvoke = new Dll(pathname); //实例化 或者satatic方法 doDllFunction show = (doDllFunction)dllinvoke.Invoke("CalcKeys1", typeof(doDllFunction)); //InitFunction为需要执行的函数名 show(ref seed[0], ref key[0]); strDatebyte += "27 " + string.Format("{0:X2}", (DataReceive[5] + 1)); for (int i = 0; i < 4; i++) { strDatebyte += " " + string.Format("{0:X2}", key[i]); } } return(strDatebyte); }
//public delegate void doDllFunction(string seed_value, string key_value); private void Security_DLL(byte[] DataReceive) { byte[] key = new byte[4]; byte[] seed = new byte[4]; strDatebyte = ""; //string KEY1 = ""; //string SEE1 = ""; for (int i = 0; i < 4; i++) { seed[i] = DataReceive[6 + i]; // SEE1 += string.Format("{0:X2}", seed[i]); } if ((DataReceive[5] == 01) || (DataReceive[5] == 03) || (DataReceive[5] == 05)) { if ((importDiag.Dll_Path) != "") { DllTest dllinvoke = new DllTest(importDiag.Dll_Path); //实例化 或者satatic方法 doDllFunction show = (doDllFunction)dllinvoke.Invoke("CalcKeys1", typeof(doDllFunction)); //InitFunction为需要执行的函数名 show(ref seed[0], ref key[0]); switch (DataReceive[5]) { case 01: strDatebyte += "27 02 "; break; case 03: strDatebyte += "27 04 "; break; case 05: strDatebyte += "27 06 "; break; default: break; } for (int i = 0; i < 4; i++) { strDatebyte += string.Format("{0:X2}", key[i]) + " "; } Transmit_Message(RequestID.Text, strDatebyte); } } }
public string SecurityAccessSeedToKey(string SeedStr, string pathname) { string Result = ""; byte[] seed = ConvertSeedToByte(SeedStr); byte[] key = new byte[seed.Length]; if (pathname != "") { Dll dllinvoke = new Dll(pathname); //实例化 或者satatic方法 doDllFunction CalculateKeyBySeed = (doDllFunction)dllinvoke.Invoke("CalcKeys", typeof(doDllFunction)); //InitFunction为需要执行的函数名 CalculateKeyBySeed(ref seed[0], ref key[0], (byte)seed.Length); for (int i = 0; i < key.Length; i++) { Result += string.Format("{0:X2}", key[i]) + " "; } } else { MessageBox.Show("Please Import Dll !!!", "Error"); } return(Result.Trim()); }