public static SoftVerifyData GetVerifyData(string soft) { RegistryKey key = Registry.LocalMachine; RegistryKey software = key.OpenSubKey("software\\" + soft); DESCrypto des = new DESCrypto(); string desstr = ""; if (software == null)//不存在 { throw (new CryptographicException("系统关键数据丢失")); // software = key.CreateSubKey("software\\" + soft);//首次运行 // desstr = des.EncryptString(DateTime.Now.ToString("yyyy-MM-dd"), "wfsoftvf", "verifyfd"); // software.SetValue("FirstTime", desstr); // desstr = des.EncryptString(DateTime.Now.ToString("yyyy-MM-dd"), "wfsoftvf", "verifycd"); // software.SetValue("CurTime", desstr); // desstr = des.EncryptString("0", "wfsoftvf", "verifyud"); // software.SetValue("UsedDays", desstr); // desstr = des.EncryptString("0", "wfsoftvf", "verifyut"); // software.SetValue("UsedTimes", desstr); } SoftVerifyData ret = new SoftVerifyData(); desstr = software.GetValue("FirstTime").ToString(); ret.FirstTime = DateTime.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyfd")); desstr = software.GetValue("CurTime").ToString(); ret.CurTime = DateTime.Parse(des.DecryptString(desstr, "wfsoftvf", "verifycd")); desstr = software.GetValue("UsedDays").ToString(); ret.UsedDays = Int32.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyud")); desstr = software.GetValue("UsedTimes").ToString(); ret.UsedTimes = Int32.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyut")); return(ret); }
public static string GetSoftData(int index) { DESCrypto des = new DESCrypto(); try { FileStream fs = new FileStream(filePath, FileMode.Open); BinaryReader sw = new BinaryReader(fs); //开始写入 fs.Seek(index * blockSize * 2, SeekOrigin.Begin); byte[] rd = sw.ReadBytes(blockSize * 2); sw.Close(); fs.Close(); string strLen = Encoding.UTF8.GetString(rd, 0, lenlen); strLen = des.DecryptString(strLen, sKey_Len, sIV_Len); int len = int.Parse(strLen); string strDes = Encoding.UTF8.GetString(rd, blockSize, len); strDes = des.DecryptString(strDes, sKey, sIV); return(strDes); } catch { throw; } }
/// <summary> /// 可选择使用 DES/RSA 双向解密函数 /// </summary> /// <param name="str">待解密的字符串</param> /// <param name="privateKeyFilePath">非对称加密的私钥文件地址</param> /// <param name="keyValue">对称加密密钥(密钥长度能且只能是8个字母)</param> /// <returns>string</returns> public static string DecryptString(string str, string privateKeyFilePath, string keyValue) { string strResult = str; if (!StringsFunction.CheckValiable(str)) { return(strResult); } // 判断非对称加密的私钥文件是否指定,指定则使用非对称加密算法(RSA)对其进行解密 if (StringsFunction.CheckValiable(privateKeyFilePath)) { string privateKey = FileOP.ReadFile(GetRealFile(privateKeyFilePath)); RSACrypto rc = new RSACrypto(); strResult = rc.RSADecrypt(privateKey, strResult); } // 判断是否指定了对称加密的密钥, 指定则采用 DES 对称加密算法进行解密 if (StringsFunction.CheckValiable(keyValue)) { DESCrypto dc = new DESCrypto(); strResult = dc.DecryptString(strResult, keyValue); } return(strResult); }
public static bool CheckEncode_DES(VerifyMachineCode_DES vc) { lcyHashCal lcy = new lcyHashCal(); DESCrypto des = new DESCrypto(); byte[] ID = StringsFunction.strToHexByte(des.DecryptString(vc.ID, "wfMaCovf", "Machincd"), ""); byte[] x = lcy.HashCal(ID, lcyNum); byte[] Encode = StringsFunction.strToHexByte(des.DecryptString(vc.Encode, "wfMaCovf", "Machincd"), ""); for (int i = 0; i < 8; i++) { if (x[i] != Encode[i]) { return(false); } } return(true); }
public static SoftVerifyData CheckVerifyData(string soft) { RegistryKey key = Registry.LocalMachine; RegistryKey software = key.OpenSubKey("software\\" + soft); DESCrypto des = new DESCrypto(); string desstr = ""; if (software == null)//不存在 { return(null); } SoftVerifyData ret = new SoftVerifyData(); desstr = software.GetValue("FirstTime").ToString(); ret.FirstTime = DateTime.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyfd")); desstr = software.GetValue("CurTime").ToString(); ret.CurTime = DateTime.Parse(des.DecryptString(desstr, "wfsoftvf", "verifycd")); desstr = software.GetValue("UsedDays").ToString(); ret.UsedDays = Int32.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyud")); desstr = software.GetValue("UsedTimes").ToString(); ret.UsedTimes = Int32.Parse(des.DecryptString(desstr, "wfsoftvf", "verifyut")); return(ret); }
public void GetVerifyData() { DESCrypto des = new DESCrypto(); try { //SetVerifyData_SoftVersion(); FileStream fs = new FileStream("Runinfo.mkt", FileMode.Open); BinaryReader sw = new BinaryReader(fs); //开始写入 fs.Seek(0, SeekOrigin.Begin); byte[] rd = sw.ReadBytes(800); sw.Close(); fs.Close(); File.SetAttributes("Runinfo.mkt", FileAttributes.System | FileAttributes.Hidden); string strLen = Encoding.UTF8.GetString(rd, 0, lenlen); strLen = des.DecryptString(strLen, sKey, sIV_Len); int len = int.Parse(strLen); string strDes = Encoding.UTF8.GetString(rd, 100, len); strDes = des.DecryptString(strDes, sKey, sIV_SoftVerion); SoftVersion = float.Parse(strDes); strLen = Encoding.UTF8.GetString(rd, 200, lenlen); strLen = des.DecryptString(strLen, sKey, sIV_Len); len = int.Parse(strLen); strDes = Encoding.UTF8.GetString(rd, 300, len); strDes = des.DecryptString(strDes, sKey, sIV_SoftUpdateTime); SoftUpdateTime = DateTime.Parse(strDes); strLen = Encoding.UTF8.GetString(rd, 400, lenlen); strLen = des.DecryptString(strLen, sKey, sIV_Len); len = int.Parse(strLen); strDes = Encoding.UTF8.GetString(rd, 500, len); strDes = des.DecryptString(strDes, sKey, sIV_LicUpdateTime); LicUpdateTime = DateTime.Parse(strDes); strLen = Encoding.UTF8.GetString(rd, 600, lenlen); strLen = des.DecryptString(strLen, sKey, sIV_Len); len = int.Parse(strLen); strDes = Encoding.UTF8.GetString(rd, 700, len); strDes = des.DecryptString(strDes, sKey, sIV_BINUpdateTime); BINUpdateTime = DateTime.Parse(strDes); } catch (FileNotFoundException) { // FileStream fs = new FileStream("Runinfo.mkt", FileMode.Create); // fs.Close(); // File.SetAttributes("Runinfo.mkt", FileAttributes.System | FileAttributes.Hidden); // BINUpdateTime = DateTime.Now.AddDays(-32); // SoftUpdateTime = DateTime.Now.AddDays(-32); // LicUpdateTime = DateTime.Now.AddDays(-32); // //SoftVersion = 车钥匙.HIDDevice.SoftVersion; // SetVerifyData_SoftVersion(); // SetVerifyData_BINUpdateTime(DateTime.Now.AddDays(-32)); // SetVerifyData_LicUpdateTime(DateTime.Now.AddDays(-32)); // SetVerifyData_SoftUpdateTime(DateTime.Now.AddDays(-32)); Make_mkt(); } catch { throw; } }