public void SA_Authenticate_Success() { DateTime expireTime = DateTime.Now.AddDays(1); //生成授权码 string authenticationCode = SecurityAuthentication.Encrypt(_checkCode, expireTime, 0, _publicKey); //认证 AuthorizationResult result = SecurityAuthentication.Authenticate(authenticationCode, _privateKey, _checkCode); Assert.IsTrue(result.Success, "未过期,结果应该是认证成功!"); }
public void SA_SA_Authenticate_FailureByExpireTime() { DateTime expireTime = new DateTime(2017, 8, 9); //生成授权码 string authenticationCode = SecurityAuthentication.Encrypt(_checkCode, expireTime, 0, _publicKey); //认证 AuthorizationResult result = SecurityAuthentication.Authenticate(authenticationCode, _privateKey, _checkCode); Assert.IsTrue(!result.Success, "当前时间超过授权期限,验证失败!"); Assert.IsTrue(result.AuthorizationState == AuthorizationState.Expire, "验证失败原因:过期!"); }
public void SA_SA_Authenticate_FailureByAuthCode() { DateTime expireTime = DateTime.Now.AddDays(1); //生成授权码 string authenticationCode = SecurityAuthentication.Encrypt(_checkCode, expireTime, 0, _publicKey); string errorAuthCode = "111111111111"; //认证 AuthorizationResult result = SecurityAuthentication.Authenticate(errorAuthCode, _privateKey, _checkCode); Assert.IsTrue(!result.Success, "授权码错误,验证失败!"); }
public void SA_SA_Authenticate_FailureByPublicKey() { DateTime expireTime = DateTime.Now.AddDays(1); //生成授权码 string authenticationCode = SecurityAuthentication.Encrypt(_checkCode, expireTime, 0, _publicKey); string errorPrivateKey = "<RSAKeyValue><Modulus>nr7rq0sgR0GokC/dTajW0MzTF1KJgeAhyxgMUhylsLcJVHqY4oo2SHs6uDYydfPd4m7t5uaaLmYdXTUfXDz9HNx9YwnuwDWy9GuNy7T9+ONENk/0hlfDs0bJKYgjcycu//QziY6WJi7yBZoTVSNmzj0takyoNqgSKLWhB20yTPk=</Modulus><Exponent>ABCD</Exponent></RSAKeyValue>"; //认证 AuthorizationResult result = SecurityAuthentication.Authenticate(authenticationCode, errorPrivateKey, _checkCode); Assert.IsTrue(!result.Success, "公钥错误,验证失败!"); }
public void SA_SA_Authenticate_FailureByCheckCode() { DateTime expireTime = DateTime.Now.AddDays(1); string errorCheckCode = "错误的校验码"; //生成授权码 string authenticationCode = SecurityAuthentication.Encrypt(_checkCode, expireTime, 0, _publicKey); //认证 AuthorizationResult result = SecurityAuthentication.Authenticate(authenticationCode, _privateKey, errorCheckCode); Assert.IsTrue(!result.Success, "校验码错误,验证失败!"); Assert.IsTrue(result.AuthorizationState == AuthorizationState.CheckCodeError, "验证失败原因:校验码错误!"); }
/// <summary> /// 生成 License Code。 /// </summary> /// <param name="entity"></param> /// <returns></returns> internal static string GeneratorLicenseCode(LicenseEntity entity) { if (entity.LicenseTarget == LicenseTarget.None) { MessageBox.Show(LicenseManagerResource.ManagerFormGetLicenseEntityAuthenticationTargetWarning, LicenseManagerResource.ManagerFormValidateParametersWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(string.Empty); } var authCode = new AuthorizationCode { ExpireTime = entity.ExpireTime, Mac = entity.MacCode, Category = entity.LicenseTarget == LicenseTarget.Development ? 0 : 1 }; var licenseCode = SecurityAuthentication.Encrypt(authCode, LicenseManagerResource.PublicKey); return(licenseCode); }