public string Decrypt(string encryptedString) { try { var tokenBytes = Convert.FromBase64String(encryptedString); string decryptedToken; using (var aes = Aes.Create()) { aes.Key = _keyBytes; aes.IV = _ivBytes; var decryptor = aes.CreateDecryptor(aes.Key, aes.IV); using (var mStream = new MemoryStream(tokenBytes)) { using (var decryptoStream = new CryptoStream(mStream, decryptor, CryptoStreamMode.Read)) { using (var streamReader = new StreamReader(decryptoStream)) { decryptedToken = streamReader.ReadToEnd(); } } } } return(decryptedToken); } catch (Exception) { throw TokenExpiredException.ThrowTokenExpiredException(); } }
private string[] ParseToken(string tokenString) { var splitToken = tokenString.Split('|'); if (splitToken.Length != TokenPartsCount) { throw TokenExpiredException.ThrowTokenExpiredException(); } return(splitToken); }
private void CheckTokenValidity(DomainToken token) { var databaseToken = _iUnitOfWork.TokenRepository.GetByGuid(token.Guid); if (databaseToken == null || databaseToken.IsExpired) { throw TokenExpiredException.ThrowTokenExpiredException(); } if (DateTime.UtcNow - databaseToken.GenerationDate <= TimeSpan.FromDays(21)) { return; } ExpireToken(token); throw TokenExpiredException.ThrowTokenExpiredException(); }