public async Task <Models.CaptchaModel> GenerateForSumQuestionCaptcha() { int Random1, Random2, RandomTotal; Random1 = new Random().Next(10, 99); Random2 = new Random().Next(10, 99); RandomTotal = Random1 + Random2; return(await Task.FromResult(new Models.CaptchaModel { CaptchaText = $"{Random1} + {Random2} = ?", CaptchaValue = await cryptoHelper.Encrypt(RandomTotal.ToString()) })); }
public void RijndaelEncrypt() { ICryptoHelper crytographyHelper = CryptoFactory.Create(CryptographyAlgorithm.Rijndael); crytographyHelper.Entropy = ENCRYPTION_VALID_PASSWORD; string encryptedString = crytographyHelper.Encrypt(ENCRYPTION_TEST_STRING, StringEncodingType.Hex); Assert.IsFalse(StringHelper.Match(encryptedString, ENCRYPTION_TEST_STRING, true), "Encrypted String Equals String Passed In"); }
public void Encrypt_red_bytes() { // arrange var bytes = "AB".ToByteArrayFromHex(); // act var encrypted = _crypto.Encrypt(bytes); var decrypted = _crypto.DecryptAsBytes(encrypted); // assert var asHex = decrypted.ToHex(); asHex .Should() .Be("AB"); encrypted .Should() .NotBe("AB", "Crypto?"); }
public void RijndaelDecryptValidPassword() { ICryptoHelper crytographyHelper = CryptoFactory.Create(CryptographyAlgorithm.Rijndael); crytographyHelper.Entropy = ENCRYPTION_VALID_PASSWORD; string encryptedString = crytographyHelper.Encrypt(ENCRYPTION_TEST_STRING, StringEncodingType.Hex); ICryptoHelper crytographyHelper2 = CryptoFactory.Create(CryptographyAlgorithm.Rijndael); crytographyHelper2.Entropy = ENCRYPTION_VALID_PASSWORD; string decriptedString = crytographyHelper2.Decrypt(encryptedString, StringEncodingType.Hex); Assert.AreEqual(ENCRYPTION_TEST_STRING, decriptedString); }
public string CreateToken(Guid appUserId, string userName) { var claims = new List <Claim> { new Claim(Constants.CLAIM_UID, _cryptoHelper.Encrypt(_configSettings.DataProtectionKey, appUserId)), new Claim(Constants.CLAIM_UNAME, _cryptoHelper.Encrypt(_configSettings.DataProtectionKey, userName)) }; //Generate Signing Credentials SymmetricSecurityKey securityKey = Helper.GenerateSecurityKey(_configuration); SigningCredentials credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature); SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), NotBefore = DateTime.Now, Expires = DateTime.Now.AddSeconds(Constants.TOKEN_EXPIRES_IN_SEC), SigningCredentials = credentials, }; JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler(); SecurityToken token = tokenHandler.CreateToken(tokenDescriptor); return(tokenHandler.WriteToken(token)); }