Rob Tiffany

Author, Software Architect, Speaker, Technology Executive, Former Navy Submariner

  • About
  • Contact Rob

Encrypting your Credentials on Windows Phone 7.5

Posted by Rob Tiffany on December 12, 2011
Posted in: Windows phone. Tagged: AES, AES 256, AesManaged, Byte Array, Credentials, Crypto, Cryptography, CryptoStream, Data, Decrypt, DPAPI, Encrypt, Encryption, IV, Key, Mango, Password, ProtectedData, Salt, Smartphone, Windows phone, Windows Phone 7, Windows Phone 7.5. 1 comment

The last time I talked to you about Windows Phone security, I showed you how to encrypt your data and save it in Isolated Storage using Silverlight’s AesManaged class to create a Key and an Initialization Vector (IV) based on a password and salt value.  This gave your consumer and line-of-business apps the iron-clad AES 256 encryption they needed to secure sensitive data.  While this made 3rd-party Windows Phone apps the most secure in the industry, users had to deal with the hassle of entering their credentials each time they launched their secure app. 

The reason users had to reenter their credentials each time is because there was no secure way to store those credentials or the key in Isolated Storage.  Having the unencrypted credentials used to create the key sitting next to the encrypted data is the same as having no security at all.  With the launch of Mango, all this has changed.

Windows Phone 7.5 gives us the Data Protection API (DPAPI) which makes it easy to encrypt and decrypt data.  It pulls this off by generating and storing a key based on the user and phone credentials.  Oh, and it gets its own decryption key, which is created the first time you run the app that’s doing the encrypting. 

Using the ProtectedData class, it’s as simple as calling the Protect method to turn an unencrypted byte array into an encrypted one.  On the flip side, you call the Unprotect method to convert an encrypted byte array into an unencrypted one.  In cases where the data stays on the phone, this may take care of all of your encryption needs and you won’t necessarily have to jump through all the AesManaged hoops I had you jump through back before we launched Windows Phone 7.  On the other hand, if you want to encrypt data on Windows Phone, send it over a network and decrypt it on a server or other endpoint, you need to stick with the stuff I taught you before.

Below is a snippet of code that shows you how to encrypt the password and salt values needed to create a key with the AesManaged class:

using System.Security.Cryptography;

//Convert Password and Salt values to byte[] arrays

byte[] PasswordByte = Encoding.UTF8.GetBytes(Password.Text);

byte[] SaltByte = Encoding.UTF8.GetBytes(Salt.Text);

//Encrypt Password and Salt byte[] arrays using Protect() method

byte[] ProtectedPasswordByte = ProtectedData.Protect(PasswordByte, null);

byte[] ProtectedSaltByte = ProtectedData.Protect(SaltByte, null);

//Save byte[] arrays as two files in Isolated Storage

…

//Read byte[] arrays from files

//Decrypt Password and Salt byte[] arrays using Unprotect() method

byte[] PasswordByte = ProtectedData.Unprotect(ProtectedPasswordByte, null);

byte[] SaltByte = ProtectedData.Unprotect(ProtectedSaltByte, null);

//Convert byte[] arrays to strings and display in the text boxes

Password.Text = Encoding.UTF8.GetString(PasswordByte, 0, PasswordByte.Length);

Salt.Text = Encoding.UTF8.GetString(SaltByte, 0, SaltByte.Length);

With this simple code above, you can now encrypt and decrypt your credentials so you can save them in Isolated Storage next to the portable, encrypted data created via the AesManaged class.  So what does this buy you?

It means your users can enter their credentials just once, no matter how many times they launch your secure application.  Hassle-free.

Stay safe out there,

Rob

  • Share this:
  • LinkedIn
  • Facebook
  • Twitter
  • Reddit
  • Print
  • Digg
  • Email
  • StumbleUpon

What Developers in Small Companies are Using

Posted by Rob Tiffany on December 9, 2011
Posted in: Software. Tagged: .NET, Bug Tracking, Database, Developer, Framework, IDE, Project Management, Software, Storage, Text Editor, Version Control, Web Hosting, Website Analytics. 1 comment

  • Share this:
  • LinkedIn
  • Facebook
  • Twitter
  • Reddit
  • Print
  • Digg
  • Email
  • StumbleUpon

Google Currents

Posted by Rob Tiffany on December 9, 2011
Posted in: Uncategorized. Tagged: Android, Google, iPad, iPhone, Reader, UI, UX. Leave a Comment

If you’re a student of beautiful, usable, minimalist user interface design, download Google Currents for iOS & Android to see what’s possible.

  • Share this:
  • LinkedIn
  • Facebook
  • Twitter
  • Reddit
  • Print
  • Digg
  • Email
  • StumbleUpon

A Quick Note on Speedy, Scalable, Available Architectures

Posted by Rob Tiffany on December 2, 2011
Posted in: Architecture. Tagged: Architecture, Availability, Cloud, Cluster, Database, Horizontal Scale, Load Balance, NoSQL, Performance, Private Cloud, Queue, Relational, Replication, Scalability, Shard, Speed, Web Service. Leave a Comment

Just a few thoughts on concepts needed to give mobile users of your SOA infrastructure the best, fastest User eXperience possible:

  • If you care about speed & scalability, your web service will always check the distributed cache before querying the database.
  • If you have to get your answer from your database, make sure to add the answer to your distributed cache concurrently with returning it to the user.
  • Don’t ever call your primary database directly.  Call one of your horizontally-scaled relational or NoSQL replicas.
  • Use download-only replication to create as many read-only replicas as you need.  Your replicas can contain complete copies of the primary database or just shards of data as appropriate.
  • When sending data up from the clients to your servers, never let your web services insert, update, or delete directly against the primary database or the replicas.
  • Have your web services drop that uploaded data in a queue and update the distributed cache while letting worker processes perform those DML operations against the primary database.
  • Use peer-to-peer replication to maintain more than one read/write primary database at the top of your hierarchy.
  • Remember to create and maintain more than one hierarchy in different geographies using the same peer-to-peer replication to provide even more availability, scalability, and performance to your mobile users all around the world.
  • Your mobile users will be connecting to your service via slow, intermittent, unpredictable wireless data networks so always use small, efficient wire protocols like REST and data serialization like JSON.

-Rob

  • Share this:
  • LinkedIn
  • Facebook
  • Twitter
  • Reddit
  • Print
  • Digg
  • Email
  • StumbleUpon

Fast Attack

Posted by Rob Tiffany on November 27, 2011
Posted in: Submarine. Tagged: Computer, Dive, Navigation, Navy, Nuclear, Ocean, SEAL, SEALs, Sonar, Stealth, Submarine, Submarine Warriors, Tomahawk, Torpedo, Virginia. Leave a Comment

Check out our newest, state of the art, fast attack submarine…the Virginia Class. Torpedoes, Tomahawks, and SEALs.

-Rob

  • Share this:
  • LinkedIn
  • Facebook
  • Twitter
  • Reddit
  • Print
  • Digg
  • Email
  • StumbleUpon

Posts navigation

← Older Entries
Newer Entries →
  • My New Novel

    Submarine Warriors

    Get the Paperback for only $9.99

    Get it on the Kindle for only $2.99

    Get it on the Nook for only $2.99

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

  • Follow Me

    RSS Feed Twitter Facebook LinkedIn

    Submarine Warriors
  • Search my Blog

  • Recent Posts

    • Books and Taxes
    • HTML5 on Windows Phone: A Simple Boilerplate
    • Submarine Warriors comes to The Dauntless Bookstore
    • Prediction: 2012 Will be the Year of Windows Phone
    • I Love what Matt Damon is doing to bring Clean Water to the World
    • Encrypting your Credentials on Windows Phone 7.5
    • What Developers in Small Companies are Using
    • Google Currents
    • A Quick Note on Speedy, Scalable, Available Architectures
    • Fast Attack
  • My Non-Fiction Books

    Book

    Get the Paperback for only $29.95

    Get it on the Kindle for only $2.99

    Book

    Get the Paperback for only $29.95

    Book

    Get the Paperback for only $49.95

    Book

    Get the Paperback for only $39.95

  • Tag Cloud

    .NET Compact Framework ADO.NET Android Azure Cloud Consumerization Data Database Gartner HTML5 IIS iPad iPhone JSON MEAP Merge Replication Microsoft Mobile Mobile Enterprise Application Platform Mobile Middleware RDA Remote Data Access REST Silverlight SQL Azure SQL CE SQL Server SQL Server Compact SSCE Sync Sync Framework Synchronize Visual Studio Visual Studio 2010 Visual Studio 2010 Express for Windows Phone WCF Windows Windows 7 Windows Azure Windows Mobile Windows phone Windows Phone 7 Windows phones Wireless XNA
  • My Speaking Events

    Event

    Event

    Magazine

    Event

    Event

  • My Magazine Articles

    Magazine

    The Microsoft Windows Mobile Line of Business Solution Accelerator 2008

    Magazine

    Getting Started with Java on PDAs

    Magazine

    JSP vs JSP

    Magazine

    Using Servlet Debugger 2.0

    Magazine

    Java Web Server and Dynamic Page Compilation

    Magazine

    How to Upgrade JBuilder's Speed and Its Servlets

    Magazine

    Servlet Development with JBuilder
Proudly powered by WordPress Theme: Parament by Automattic.
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.