HIR 临时web
	
		
			
	
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
					Details
				
			
		
	
				
					
				
			
				
	
				continuous-integration/drone/push Build is passing
				
					Details
				
			
		
	
							parent
							
								
									f81cf9c2f2
								
							
						
					
					
						commit
						9827ffa0f2
					
				| 
						 | 
				
			
			@ -44,26 +44,24 @@ public class HIRActivateService : ServiceBase
 | 
			
		|||
    /// <summary>
 | 
			
		||||
    /// 获取项目激活码
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="decodedText"></param>
 | 
			
		||||
    /// <param name="_basicSystemConfigConfig"></param>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    [AllowAnonymous]
 | 
			
		||||
    [RoutePattern(HttpMethod = "get")]
 | 
			
		||||
    public async Task<IResponseOutput> GetTrialActivationCode(string decodedText, [FromServices] IOptionsMonitor<ServiceVerifyConfigOption> _basicSystemConfigConfig)
 | 
			
		||||
    public async Task<IResponseOutput> GetTrialActivationCode(TrialAuthorizationInfo authorizationInfo, [FromServices] IOptionsMonitor<ServiceVerifyConfigOption> _basicSystemConfigConfig)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        var authorizationInfo = JsonConvert.DeserializeObject<TrialAuthorizationInfo>(decodedText);
 | 
			
		||||
 | 
			
		||||
        if (authorizationInfo != null)
 | 
			
		||||
        {
 | 
			
		||||
            //一周内激活
 | 
			
		||||
            authorizationInfo.ActiveDeadLineDate = DateTime.Now.Date.AddDays(8).AddSeconds(-1);
 | 
			
		||||
            var info = Cryptography.EncryptString($"{JsonConvert.SerializeObject(authorizationInfo)}", "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
 | 
			
		||||
 | 
			
		||||
            Console.WriteLine("HIR_System_AES_Key_Info".PadRight(32, '0').Substring(0, 32)+"    "+ "Trial_AuthorizationEncrypt".PadRight(16, '0').Substring(0, 16));
 | 
			
		||||
            var enCrept = AesEncryption.Encrypt($"{JsonConvert.SerializeObject(authorizationInfo)}", "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
 | 
			
		||||
            var info = AesEncryption.Encrypt($"{JsonConvert.SerializeObject(authorizationInfo)}", "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
 | 
			
		||||
 | 
			
		||||
            var dd= AesEncryption.Decrypt(enCrept, "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
 | 
			
		||||
            Console.WriteLine("HIR_System_AES_Key_Info".PadRight(32, '0').Substring(0, 32) + "    " + "Trial_AuthorizationEncrypt".PadRight(16, '0').Substring(0, 16));
 | 
			
		||||
 | 
			
		||||
            //var dd = AesEncryption.Decrypt(info, "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
 | 
			
		||||
 | 
			
		||||
            return ResponseOutput.Ok(info);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -101,60 +99,3 @@ public class TrialAuthorizationInfo
 | 
			
		|||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public class Cryptography
 | 
			
		||||
{
 | 
			
		||||
    public static string EncryptString(string plainText, string key, string iv)
 | 
			
		||||
    {
 | 
			
		||||
        using (Aes aesAlg = Aes.Create())
 | 
			
		||||
        {
 | 
			
		||||
            aesAlg.Key = GetKeyBytes(key, aesAlg.KeySize / 8);
 | 
			
		||||
            aesAlg.IV = GetKeyBytes(iv, 16);
 | 
			
		||||
 | 
			
		||||
            ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
 | 
			
		||||
 | 
			
		||||
            using (MemoryStream msEncrypt = new MemoryStream())
 | 
			
		||||
            {
 | 
			
		||||
                using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
 | 
			
		||||
                {
 | 
			
		||||
                    byte[] plainBytes = Encoding.UTF8.GetBytes(plainText);
 | 
			
		||||
                    csEncrypt.Write(plainBytes, 0, plainBytes.Length);
 | 
			
		||||
                    csEncrypt.FlushFinalBlock();
 | 
			
		||||
                }
 | 
			
		||||
                return Convert.ToBase64String(msEncrypt.ToArray());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static string DecryptString(string cipherText, string key, string iv)
 | 
			
		||||
    {
 | 
			
		||||
        byte[] cipherBytes = Convert.FromBase64String(cipherText);
 | 
			
		||||
        using (Aes aesAlg = Aes.Create())
 | 
			
		||||
        {
 | 
			
		||||
            aesAlg.Key = GetKeyBytes(key, aesAlg.KeySize / 8);
 | 
			
		||||
            aesAlg.IV = GetKeyBytes(iv, 16);
 | 
			
		||||
 | 
			
		||||
            ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
 | 
			
		||||
 | 
			
		||||
            using (MemoryStream msDecrypt = new MemoryStream(cipherBytes))
 | 
			
		||||
            {
 | 
			
		||||
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
 | 
			
		||||
                {
 | 
			
		||||
                    using (StreamReader srDecrypt = new StreamReader(csDecrypt))
 | 
			
		||||
                    {
 | 
			
		||||
                        return srDecrypt.ReadToEnd();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static byte[] GetKeyBytes(string key, int keySize)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        using (var deriveBytes = new PasswordDeriveBytes(key, null))
 | 
			
		||||
        {
 | 
			
		||||
            return deriveBytes.GetBytes(keySize);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue