public MerchantApiData GetMerchantApiData() { try { var fidelitySettings = _orchardServices.WorkContext.CurrentSite.As <FidelitySiteSettingsPart>(); MerchantApiData result = new MerchantApiData(); result.Success = true; if (String.IsNullOrWhiteSpace(fidelitySettings.MerchantSessionId) || String.IsNullOrWhiteSpace(fidelitySettings.PlaceId)) { ConfigEnv configData = GetConfigData(); MLogin merchantLogin = new MLogin(); merchantLogin.username = fidelitySettings.MerchantUsername; merchantLogin.password = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(fidelitySettings.MerchantPwd))); ILoyalzooMerchant m = new Merchant(); MResultLogin loginResult = m.Login(configData, merchantLogin); if (loginResult.success) { fidelitySettings.MerchantSessionId = loginResult.response.session_id; fidelitySettings.PlaceId = loginResult.response.place_id; } else { result.Success = false; result.ErrorMessage = loginResult.Errore.response; } } if (result.Success) { result.MerchantId = (string)fidelitySettings.MerchantSessionId; result.PlaceId = (string)fidelitySettings.PlaceId; result.ErrorMessage = ""; } else { result.MerchantId = result.PlaceId = ""; } return(result); } catch (Exception ex) { return(new MerchantApiData { MerchantId = "", PlaceId = "", Success = false, ErrorMessage = ex.Message }); } }
private void lazyLoadHandlers(SocrataSettingsPart part) { //decrypt stored password on read part.PasswordField.Getter(() => { try { var encryptedPassword = part.Retrieve(x => x.Password); return(String.IsNullOrWhiteSpace(encryptedPassword) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(encryptedPassword)))); } catch { Logger.Error("The Socrata password could not be decrypted. It might be corrupted, try to reset it."); return(null); } }); // encrypt plaintext password on write part.PasswordField.Setter(value => { var encryptedPassword = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value))); part.Store(x => x.Password, encryptedPassword); }); }
public UserIdamData GetUserIdamDataFromCookie(HttpContext context) { var cookie = new CookieHelper(Settings.UserDataCookieName, context); cookie.GetCookie(); var encodedJwtToken = cookie.GetValue(Settings.UserDataCookieKey); if (string.IsNullOrEmpty(encodedJwtToken)) { return(null); } var jwtToken = _encryptionService.Decode(encodedJwtToken); IEnumerable <Claim> claims; try { claims = _jwtTokenService.GetClaimsFromJwtToken(jwtToken, Settings.JwtTokenSecurityKey); } catch (Exception) { //_logManager.LogError("GetUserDataFromCookie failed", ex, this); // Uncomment for debug purposes return(null); } return(new UserIdamData(claims)); }
public string DecryptApiKey() { var settings = _orchardServices.WorkContext.CurrentSite.As <MailchimpSiteSettings>(); var apiKey = _encryptionService.Decode(Convert.FromBase64String(settings.ApiKey ?? "")); return(Encoding.UTF8.GetString(apiKey)); }
public string GetSecret(ApiCredentialsPart part) { if (string.IsNullOrWhiteSpace(part.ApiSecret)) { return(part.ApiSecret); } // decryption return(Encoding.UTF8.GetString( _encryptionService.Decode( Convert.FromBase64String(part.ApiSecret)))); }
public bool TryDeserializeProviderUserId(string data, out string providerName, out string providerUserId) { Argument.ThrowIfNullOrEmpty(data, "data"); var protectedBytes = _encryptionService.Decode(Convert.FromBase64String(data)); var provider = (SerializedProvider)ToObject(protectedBytes); providerName = provider.ProviderName; providerUserId = provider.ProviderUserId; return(true); }
public IUser ValidateHash(string Hash, string ApiKey) { try { var logins = from login in _loginsRepository.Table where login.Hash == Hash select login; if (logins == null) { return(null); } var loginrecord = logins.FirstOrDefault(); if (loginrecord == null) { return(null); } var data = _encryptionService.Decode(Convert.FromBase64String(loginrecord.Hash)); var xml = Encoding.UTF8.GetString(data); var element = XElement.Parse(xml); DateTime validateByUtc; string appid = element.Attribute("ai").Value; string userid = element.Attribute("ui").Value; validateByUtc = DateTime.Parse(element.Attribute("utc").Value, CultureInfo.InvariantCulture); if (_clock.UtcNow <= validateByUtc) { int aid; ApplicationRecord app = null; if (Int32.TryParse(appid, out aid)) { app = _applicationsService.GetApplication(aid); } if (app != null && app.AppKey == ApiKey) { int uid; if (Int32.TryParse(userid, out uid)) { return(GetUser(uid)); } } } else { _loginsRepository.Delete(loginrecord); return(null); } } catch { return(null); } return(null); }
public static string DecodePassword(string value, IEncryptionService encryptionService, Func<string> failureHandler) { try { return string.IsNullOrWhiteSpace(value) ? string.Empty : Encoding.UTF8.GetString(encryptionService.Decode(Convert.FromBase64String(value))); } catch { return failureHandler(); } }
/// <summary> /// Ritorna l'il FidelityCustomer associato all'User autenticato su Orchard /// </summary> /// <returns>FidelityCustomer se esiste un utente autenticato, null altrimenti</returns> public virtual FidelityCustomer GetCustomerFromAuthenticatedUser() { var authenticatedUser = _authenticationService.GetAuthenticatedUser(); if (authenticatedUser != null) { FidelityUserPart fidelityPart = (FidelityUserPart)(((dynamic)authenticatedUser.ContentItem).FidelityUserPart); if (fidelityPart != null && !String.IsNullOrWhiteSpace(fidelityPart.FidelityUsername) && !String.IsNullOrWhiteSpace(fidelityPart.FidelityPassword) ) { string pass = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(fidelityPart.FidelityPassword))); FidelityCustomer customer = new FidelityCustomer(authenticatedUser.Email, fidelityPart.FidelityUsername, pass); if (String.IsNullOrWhiteSpace(fidelityPart.CustomerId)) { fidelityPart.CustomerId = _sendService.SendCustomerDetails(settingsPart, customer).data.Id; } customer.Id = fidelityPart.CustomerId; return(customer); } } return(null); }
public bool DecryptNonce(string nonce, out int id) { id = 0; try { var data = _encryptionService.Decode(Convert.FromBase64String(nonce)); var xml = Encoding.UTF8.GetString(data); var element = XElement.Parse(xml); id = Convert.ToInt32(element.Attribute("c").Value); var validateByUtc = DateTime.Parse(element.Attribute("v").Value, CultureInfo.InvariantCulture); return(_clock.UtcNow <= validateByUtc); } catch { return(false); } }
public bool DecryptNonce(string nonce, out string username, out DateTime validateByUtc) { username = null; validateByUtc = _clock.UtcNow; try { var data = _encryptionService.Decode(Convert.FromBase64String(nonce)); var xml = Encoding.UTF8.GetString(data); var element = XElement.Parse(xml); username = element.Attribute("un").Value; validateByUtc = DateTime.Parse(element.Attribute("utc").Value, CultureInfo.InvariantCulture); return(_clock.UtcNow <= validateByUtc); } catch { return(false); } }
public bool DecryptNonce(string nonce, out int contentItemId, out string signal) { contentItemId = 0; signal = ""; try { var data = _encryptionService.Decode(Convert.FromBase64String(nonce)); var xml = Encoding.UTF8.GetString(data); var element = XElement.Parse(xml); contentItemId = Convert.ToInt32(element.Attribute("c").Value); signal = element.Attribute("n").Value; return(true); } catch { return(false); } }
public PaypalSettings GetSettings() { var settingsPart = Services.WorkContext.CurrentSite.As <OShopPaypalSettingsPart>(); var settings = new PaypalSettings() { UseSandbox = settingsPart.UseSandbox, ClientId = settingsPart.ClientId, }; if (!string.IsNullOrEmpty(settingsPart.ClientSecret)) { settings.ClientSecret = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(settingsPart.ClientSecret))); } return(settings); }
void LazyLoadHandlers(LoadContentContext context, SmtpSettingsPart part) { part.PasswordField.Getter(() => { try { var encryptedPassword = part.Retrieve(x => x.Password); return(String.IsNullOrWhiteSpace(encryptedPassword) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(encryptedPassword)))); } catch { Logger.Error("The email password could not be decrypted. It might be corrupted, try to reset it."); return(null); } }); part.PasswordField.Setter(value => { var encryptedPassword = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value))); part.Store(x => x.Password, encryptedPassword); }); part.AddressPlaceholderField.Loader(value => (string)((dynamic)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From); }
private bool ValidatePasswordEncrypted(UserPart userPart, string password) { return(String.Equals(password, Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(userPart.Password))), StringComparison.Ordinal)); }
private void LazyLoadHandlers(LoadContentContext context, IMAPSettingPart part) { part.PasswordField.Getter(() => { try { var encryptedPassword = part.Retrieve(x => x.Password); return(String.IsNullOrWhiteSpace(encryptedPassword) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(encryptedPassword)))); } catch { Logger.Error("The email password could not be decrypted. It might be corrupted, try to reset it."); return(null); } }); part.PasswordField.Setter(value => { var encryptedPassword = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value))); part.Store(x => x.Password, encryptedPassword); }); }
void LazyLoadHandlers(LoadContentContext context, TwilioSettingsPart part) { part.AuthTokenField.Getter(() => { try { var encryptedAuthToken = part.Retrieve(x => x.AuthToken); return(String.IsNullOrWhiteSpace(encryptedAuthToken) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(encryptedAuthToken)))); } catch { Logger.Error("The Twilio authtoken password could not be decrypted. It might be corrupted, try to reset it."); return(null); } }); part.AuthTokenField.Setter(value => { var encryptedAuthToken = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value))); part.Store(x => x.AuthToken, encryptedAuthToken); }); }
public static string Cleartext(this IEncryptionService service, string ciphertext) { return(service.Decode(ciphertext.FromBase64String()).GetString()); }
public MarkdownRepoPartHandler( IMarkdownContentItemManager markdownContentItemManager, IRepository <MarkdownRepoPartRecord> repository, IScheduledTaskManager scheduledTaskManager, IClock clock, IContentManager contentManager, IEncryptionService encryptionService) { Filters.Add(StorageFilter.For(repository)); OnActivated <MarkdownRepoPart>((context, part) => { part.AccessTokenField.Loader(() => { return(string.IsNullOrEmpty(part.EncodedAccessToken) ? "" : Encoding.UTF8.GetString(encryptionService.Decode(Convert.FromBase64String(part.EncodedAccessToken)))); }); part.AccessTokenField.Setter((value) => { part.EncodedAccessToken = string.IsNullOrEmpty(value) ? "" : Convert.ToBase64String(encryptionService.Encode(Encoding.UTF8.GetBytes(value))); return(value); }); part.PasswordField.Loader(() => { return(string.IsNullOrEmpty(part.EncodedPassword) ? "" : Encoding.UTF8.GetString(encryptionService.Decode(Convert.FromBase64String(part.EncodedPassword)))); }); part.PasswordField.Setter((value) => { part.EncodedPassword = string.IsNullOrEmpty(value) ? "" : Convert.ToBase64String(encryptionService.Encode(Encoding.UTF8.GetBytes(value))); return(value); }); }); OnRemoved <MarkdownRepoPart>((ctx, part) => { scheduledTaskManager.DeleteTasks(part.ContentItem); if (part.DeleteMarkdownPagesOnRemoving == true) { markdownContentItemManager.DeleteAll(part); } // Since the repo is deleted we doesn't want to prevent the deletion of the markdown pages. else { var correspondingMarkdownPages = contentManager .Query(part.ContentType) .Where <MarkdownPagePartRecord>(record => record.MarkdownRepoId == part.ContentItem.Id) .List(); foreach (var correspondingMarkdownPage in correspondingMarkdownPages) { correspondingMarkdownPage.As <MarkdownPagePart>().DeletionAllowed = true; } } }); OnPublished <MarkdownRepoPart>((ctx, part) => { if (ctx.PreviousItemVersionRecord != null) { scheduledTaskManager.DeleteTasks(part.ContentItem); } scheduledTaskManager .CreateTask( TaskNameHelper.GetMarkdownContentUpdaterTaskName(part.ContentItem), clock.UtcNow.AddMinutes(1), part.ContentItem); }); }
public static string Decrypt(this IEncryptionService service, string value) { return(Encoding.UTF8.GetString(service.Decode(Convert.FromBase64String(value)))); }
public static string GetDecodedPassword(this BitbucketRepositoryDataRecord settings, IEncryptionService encryptionService) { return Encoding.UTF8.GetString(encryptionService.Decode(Convert.FromBase64String(settings.Password))); }
public ActionResult GetSecureFile(int id, string fieldName) { var accessGranted = false; WorkContext wc = _services.WorkContext; IUser user = _services.WorkContext.CurrentUser; if (!String.IsNullOrEmpty(wc.CurrentSite.SuperUser) && user != null && String.Equals(user.UserName, wc.CurrentSite.SuperUser, StringComparison.Ordinal)) { accessGranted = true; } var content = _services.ContentManager.Get <ContentPart>(id); if (content == null) { return(RedirectToAction("NotFound")); } var part = content.ContentItem.As <ContentPermissionsPart>(); // if the content item has no right attached, check on the container if (part == null || !part.Enabled) { var commonPart = part.As <CommonPart>(); if (commonPart != null && commonPart.Container != null) { part = commonPart.As <ContentPermissionsPart>(); } } //if we do not have access level permissions for this content item then we need to check if user can view the content if (part == null || !part.Enabled) { accessGranted = _authorizationService.TryCheckAccess(Permissions.ViewContent, user, content); } else { var hasOwnership = HasOwnership(user, content.ContentItem); IEnumerable <string> authorizedRoles; //we only care about view permission in this field authorizedRoles = (hasOwnership ? part.ViewOwnContent : part.ViewContent).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // determine what set of roles should be examined by the access check IEnumerable <string> rolesToExamine; if (user == null) { rolesToExamine = AnonymousRole; } else if (user.Has <IUserRoles>()) { // the current user is not null, so get his roles and add "Authenticated" to it rolesToExamine = user.As <IUserRoles>().Roles; // when it is a simulated anonymous user in the admin if (!rolesToExamine.Contains(AnonymousRole[0])) { rolesToExamine = rolesToExamine.Concat(AuthenticatedRole); } } else { // the user is not null and has no specific role, then it's just "Authenticated" rolesToExamine = AuthenticatedRole; } accessGranted = rolesToExamine.Any(x => authorizedRoles.Contains(x, StringComparer.OrdinalIgnoreCase)); } if (accessGranted) { var field = (Fields.SecureFileField)(content.ContentItem).Parts.SelectMany(p => p.Fields).First(f => f.Name == fieldName); var settings = field.PartFieldDefinition.Settings.GetModel <SecureFileFieldSettings>(); IStorageProvider provider; if (!string.IsNullOrEmpty(settings.SecureBlobAccountName)) { provider = new SecureAzureBlobStorageProvider(settings.SecureBlobAccountName, settings.SecureSharedKey, settings.SecureBlobEndpoint, true, settings.SecureDirectoryName); } else { // I need to check if, by setting, the file is in a subfolder. string repo = settings.SecureDirectoryName; if (!string.IsNullOrWhiteSpace(field.Subfolder)) { repo = Path.Combine(repo, field.Subfolder); } provider = new SecureFileStorageProvider(repo); } if (!provider.Exists(field.Url)) { return(RedirectToAction("NotFound")); } IStorageFile file = provider.Get <StorageFile>(field.Url); Stream fs = new MemoryStream(file.FileBytes); if (settings.EncryptFile) { byte[] fileBytes = new byte[fs.Length]; fs.Read(fileBytes, 0, (int)fs.Length); fileBytes = _encryptionService.Decode(fileBytes); fs = new MemoryStream(fileBytes); } string mimeType = MimeMapping.GetMimeMapping(file.FileName); return(new FileStreamResult(fs, mimeType)); } return(RedirectToAction("NotFound")); }
void LazyLoadHandlers(LoadContentContext context, AdSettingsPart part) { part.PasswordField.Getter(() => { try { return(string.IsNullOrWhiteSpace(part.Record.Password) ? string.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(part.Record.Password)))); } catch { Logger.Error("The Ad Settings password could not be decrypted. It might be corrupted, try to reset it."); return(null); } }); part.PasswordField.Setter(value => part.Record.Password = string.IsNullOrWhiteSpace(value) ? string.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value)))); }