Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (149).NET Core  (24)Angular  (42)ASP.NET  (48)ASP.NET Core  (56)ASP.NET MVC  (84)Azure  (28)Blazor  (68)DocIO  (18)Essential JS 2  (67)Essential Studio  (161)Flutter  (76)JavaScript  (139)Microsoft  (101)PDF  (54)React  (30)Succinctly series  (120)Syncfusion  (457)TypeScript  (30)Uno Platform  (2)UWP  (4)Vue  (26)Webinar  (16)Windows Forms  (54)WPF  (105)Xamarin  (116)XlsIO  (22)Other CategoriesBarcode  (4)BI  (29)Bold BI  (3)Build conference  (6)Business intelligence  (53)Button  (4)C#  (104)Chart  (43)Cloud  (9)Company  (445)Dashboard  (6)Data Science  (3)Data Validation  (3)DataGrid  (36)Development  (244)Doc  (7)DockingManager  (1)eBook  (91)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (16)Extensions  (9)File Manager  (3)Gantt  (7)Gauge  (5)Git  (3)Grid  (25)HTML  (9)Installer  (2)Knockout  (2)LINQPad  (1)Linux  (1)M-Commerce  (1)Metro Studio  (11)Mobile  (176)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (18)Performance  (2)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (5)Road Map  (9)Scheduler  (18)SfDataGrid  (8)Silverlight  (21)Sneak Peek  (14)Solution Services  (2)Spreadsheet  (3)SQL  (5)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (9)Tips and Tricks  (39)UI  (97)Uncategorized  (68)Unix  (2)User interface  (64)Visual State Manager  (1)Visual Studio  (15)Visual Studio Code  (8)Web  (150)What's new  (95)Windows 8  (19)Windows App  (1)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
Protecting sensitive data in Xamarin Forms app

Protecting Sensitive Data in the Background in Xamarin.Forms

Information security is as simple as ABC: always be careful.

                                                                                                        —Anonymous

Nowadays, mobile applications have become our daily bread. They are essential tools for developing our digital lives. We do everything through apps. We manage our bank accounts, listen to music, inform ourselves, read the news, share on social networks, and so on.

We know that we use each application for our convenience, but every time we install a new one, are we aware of the permissions we will grant it? That is, do we know the security level of any application?

I imagine everyone’s answer is a resounding no. And what we do know is that comfort and safety are antagonistic: the higher one is, the lower the other, and vice versa.

Privacy by default

The concept of privacy by default means that applications, software, or systems, from the moment they are created, should take measures to protect a user’s information (i.e. they should provide a data security facility).

For this, there are already methodologies that review the application code itself and provide guidelines for security, including data encryption, SSL-TLS protocols, vulnerability tests, audits, authentication mechanisms, storage, etc.

Just a few…

Certain applications have recently improved their features regarding the security they offer to users, such as PayPal, WhatsApp, and of course all banking applications. If we pay attention to any of them, we can see that they have a function to protect confidential information in the background.

But how do they do it?

The answer is super simple, so let’s see how we can do it in our Xamarin.Forms applications.

Let’s start with iOS

To protect our confidential information on Apple devices, we should go to the AppDelegate.cs file and enter the following methods:

  • OnResignActivation – Helps us block the content.
  • OnActivated – Helps us unlock the content.

Refer to the following code example.

using UIKit;
using Foundation;
using System.Linq;
 
namespace SensitiveData.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
 
        public override void OnResignActivation(UIApplication application)
        {
            var blurEffect = UIBlurEffect.FromStyle(UIBlurEffectStyle.ExtraDark);
            var blurEffectView = new UIVisualEffectView(blurEffect)
            {
                Frame = application.KeyWindow.Subviews.First().Bounds,
                AutoresizingMask = UIViewAutoresizing.FlexibleDimensions,
                Tag = 12
            };
            application.KeyWindow.Subviews.Last().AddSubview(blurEffectView);
            base.OnResignActivation(application);
        }
 
        public override void OnActivated(UIApplication uiApplication)
        {
            var sub = uiApplication.KeyWindow?.Subviews.Last();
            if (sub == null)
                return;
            foreach (var vv in sub.Subviews)
            {
                if (vv.Tag == 12)
                    vv.RemoveFromSuperview();
            }
            base.OnActivated(uiApplication);
        }
 
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());
 
            return base.FinishedLaunching(app, options);
        }
    }
}

On Android

Now for Android, we need to go to the MainActivity.cs file and do practically the same thing we did for iOS but in the OnPause and OnResume methods, like in the following code:

protected override void OnResume()
{
    Window.ClearFlags(WindowManagerFlags.Secure);
    base.OnResume();
}
protected override void OnPause()
{
    Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
    base.OnPause();
}

Result:

Protecting Sensitive Data in iOS
Android
Protecting Sensitive Data in Android
iOS
Images Source: Vicente Guzman GitHub

GitHub Reference: You can download the full code from GitHub.

Conclusion

For developers, application user’s data can be protected by following the steps provided in this blog post.

For the mobile application users, it is clear that if they want to protect their privacy and make their data safe (or less exposed), they must, in addition to reviewing the permissions of each application one by one, sacrifice comfort a little and perform a couple (or a few) more clicks instead of leaving all the settings as the developers of those apps would like them to be: 100% accessible.

So, use the tips given in this post and safeguard your sensitive data from unauthorized persons.

Happy coding!

About Syncfusion

Syncfusion offers over 150 UI controls for Xamarin, from basic editors to powerful, advanced controls like the DataGrid, Charts, ListView, and RTE controls. Use them to build charming applications!

If you want to send us feedback, please use the comments section below. You can also reach us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

If you like this post, we think you will also like the following:

Tags:

Share this post:

Share on twitter
Share on facebook
Share on linkedin

Leave a comment

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top