/// <summary> /// <para>LockCode - Interface Method. Computes a lock code corresponding to the specified Lock Types, License Class, etc.</para> /// <para>Optionally, if a product license is specified, then a lock string specific to that license is returned.</para> /// </summary> /// <param name="Lic">Optional - ByRef Lic As ProductLicense - Product License for which to compute the lock code.</param> /// <returns>String - Lock code</returns> /// <remarks></remarks> public string LockCode( [ System.Runtime.InteropServices.OptionalAttribute, System.Runtime.InteropServices.DefaultParameterValueAttribute(null) ] ref ProductLicense Lic) { return(string.Empty); }
string _IALUGenerator.GenKey(ref ActiveLock3_6NET.ProductLicense Lic, string InstCode, [System.Runtime.InteropServices.OptionalAttribute, System.Runtime.InteropServices.DefaultParameterValueAttribute("0")] // ERROR: Optional parameters aren't supported in C# string RegisteredLevel) { return(IALUGenerator_GenKey(Lic, InstCode, RegisteredLevel)); }
//=============================================================================== // Name: Function IALUGenerator_GenKey // Input: // ByRef Lic As ActiveLock3.ProductLicense - Product license // ByVal InstCode As String - Installation Code sent by the user // ByVal RegisteredLevel As String - Registration Level for the license. Default is "0" // Output: // String - Liberation key for the license // Purpose: Given the Installation Code, generates an Activelock license liberation key. // Remarks: None //=============================================================================== private string IALUGenerator_GenKey(ref ActiveLock3_6NET.ProductLicense Lic, string InstCode, [System.Runtime.InteropServices.OptionalAttribute, System.Runtime.InteropServices.DefaultParameterValueAttribute("0")] // ERROR: Optional parameters aren't supported in C# string RegisteredLevel) { // Take request code and decrypt it. string strReq = null; // 05.13.05 - ialkan Modified to merge DLLs into one strReq = modBase64.Base64_Decode(ref InstCode); // strReq now contains the {LockCode + vbLf + User} string string strLock = string.Empty; string strUser = string.Empty; GetLockAndUserFromInstallCode(strReq, ref strLock, ref strUser); Lic.Licensee = strUser; // registration date string strRegDate = null; // registered level Lic.RegisteredLevel = RegisteredLevel; strRegDate = Lic.RegisteredDate; string strEncrypted = null; // @todo Rethink this bit about encrypting the dates. // We need to keep in mind that the app does not have access to the private key, so and any decryption that requires private key // would not be possible. // Perhaps instead of encrypting, we could do MD5 hash of (regdate+lockcode)? //ActiveLockEventSink_ValidateValue strRegDate, strEncrypted // hash it //strEncrypted = ActiveLock3.MD5Hash(strEncrypted) strEncrypted = strRegDate; // get software codes ProductInfo ProdInfo = null; ProdInfo = IALUGenerator_RetrieveProduct(Lic.ProductName, Lic.ProductVer); Lic.ProductKey = ProdInfo.VCode; string strLic = null; strLic = Lic.ToString_Renamed() + Constants.vbLf + strLock; System.Diagnostics.Debug.WriteLine("strLic: " + Constants.vbCrLf + strLic); if (modALUGEN.strLeft(ProdInfo.VCode, 3) != "RSA") { // sign it string strSig = null; strSig = new string(Strings.Chr(0), 1024); // 05.13.05 - ialkan Modified to merge DLLs into one. Moved RSASign into a module strSig = modActiveLock.RSASign(ProdInfo.VCode, ProdInfo.GCode, strLic); // Create liberation key. This will be a base-64 encoded string of the whole license. string strLicKey = null; // 05.13.05 - ialkan Modified to merge DLLs into one strLicKey = modBase64.Base64_Encode(ref strSig); // update Lic with license key Lic.LicenseKey = strLicKey; // Print some info for debugging purposes System.Diagnostics.Debug.WriteLine("VCode: " + ProdInfo.VCode); System.Diagnostics.Debug.WriteLine("Lic: " + strLic); System.Diagnostics.Debug.WriteLine("Lic hash: " + modMD5.Hash(ref strLic)); System.Diagnostics.Debug.WriteLine("LicKey: " + strLicKey); System.Diagnostics.Debug.WriteLine("Sig: " + strSig); System.Diagnostics.Debug.WriteLine("Verify: " + modActiveLock.RSAVerify(ProdInfo.VCode, strLic, modBase64.Base64_Decode(ref strLicKey))); System.Diagnostics.Debug.WriteLine("===================================================="); } else { try { System.Security.Cryptography.RSACryptoServiceProvider rsaCSP = new System.Security.Cryptography.RSACryptoServiceProvider(); string strPublicBlob = null; string strPrivateBlob = null; strPublicBlob = ProdInfo.VCode; strPrivateBlob = ProdInfo.GCode; if (modALUGEN.strLeft(ProdInfo.GCode, 6) == "RSA512") { strPrivateBlob = modALUGEN.strRight(ProdInfo.GCode, Strings.Len(ProdInfo.GCode) - 6); } else { strPrivateBlob = modALUGEN.strRight(ProdInfo.GCode, Strings.Len(ProdInfo.GCode) - 7); } // import private key params into instance of RSACryptoServiceProvider rsaCSP.FromXmlString(strPrivateBlob); RSAParameters rsaPrivateParams = default(RSAParameters); //stores private key rsaPrivateParams = rsaCSP.ExportParameters(true); rsaCSP.ImportParameters(rsaPrivateParams); byte[] userData = Encoding.UTF8.GetBytes(strLic); AsymmetricSignatureFormatter asf = new RSAPKCS1SignatureFormatter(rsaCSP); HashAlgorithm algorithm = new SHA1Managed(); asf.SetHashAlgorithm(algorithm.ToString()); byte[] myhashedData = null; // a byte array to store hash value string myhashedDataString = null; myhashedData = algorithm.ComputeHash(userData); myhashedDataString = BitConverter.ToString(myhashedData).Replace("-", string.Empty); byte[] mysignature = null; // holds signatures mysignature = asf.CreateSignature(algorithm); string mySignatureBlock = null; mySignatureBlock = Convert.ToBase64String(mysignature); Lic.LicenseKey = mySignatureBlock; } catch (Exception ex) { modActiveLock.Set_Locale(modActiveLock.regionalSymbol); Err().Raise(AlugenGlobals.alugenErrCodeConstants.alugenProdInvalid, modTrial.ACTIVELOCKSTRING, ex.Message); } } // Serialize it into a formatted string string strLibKey = string.Empty; Lic.Save(ref strLibKey); return(strLibKey); }