AES Encryption for Windows Phone

Hi,
We are developing a windows phone app and the same app is also being developed in Android and IOS. All three platforms are using a JSON web service for data access. Parameters to be passed are encrypted using AES algorithm.
The web service uses the Encryption and Decryption as shown in the following link : 
https://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged(v=vs.110).aspx
The same is Encryption is available in IOS and Android and working fine.
I am unable to achieve the same encryption in Windows Phone as System.Security.Cryptography is not available in Windows Phone. I did browse around and found a few alternatives as shown below but i am not getting the desired result i.e. Encrypted data is
not the same and hence Decryption is not giving the same result in server side.
public static byte[] Encrypt(string plainText, string pw, string salt)
IBuffer pwBuffer = CryptographicBuffer.ConvertStringToBinary(pw, BinaryStringEncoding.Utf8);
IBuffer saltBuffer = CryptographicBuffer.ConvertStringToBinary(salt, BinaryStringEncoding.Utf16LE);
IBuffer plainBuffer = CryptographicBuffer.ConvertStringToBinary(plainText, BinaryStringEncoding.Utf16LE);
// Derive key material for password size 32 bytes for AES256 algorithm
KeyDerivationAlgorithmProvider keyDerivationProvider = Windows.Security.Cryptography.Core.KeyDerivationAlgorithmProvider.OpenAlgorithm("PBKDF2_SHA1");
// using salt and 1000 iterations
KeyDerivationParameters pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(saltBuffer, 1000);
// create a key based on original key and derivation parmaters
CryptographicKey keyOriginal = keyDerivationProvider.CreateKey(pwBuffer);
IBuffer keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms, 32);
CryptographicKey derivedPwKey = keyDerivationProvider.CreateKey(pwBuffer);
// derive buffer to be used for encryption salt from derived password key
IBuffer saltMaterial = CryptographicEngine.DeriveKeyMaterial(derivedPwKey, pbkdf2Parms, 16);
// display the buffers – because KeyDerivationProvider always gets cleared after each use, they are very similar unforunately
string keyMaterialString = CryptographicBuffer.EncodeToBase64String(keyMaterial);
string saltMaterialString = CryptographicBuffer.EncodeToBase64String(saltMaterial);
SymmetricKeyAlgorithmProvider symProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm("AES_CBC_PKCS7");
// create symmetric key from derived password key
CryptographicKey symmKey = symProvider.CreateSymmetricKey(keyMaterial);
// encrypt data buffer using symmetric key and derived salt material
IBuffer resultBuffer = CryptographicEngine.Encrypt(symmKey, plainBuffer, saltMaterial);
byte[] result;
CryptographicBuffer.CopyToByteArray(resultBuffer, out result);
return result;
public static string Decrypt(byte[] encryptedData, string pw, string salt)
IBuffer pwBuffer = CryptographicBuffer.ConvertStringToBinary(pw, BinaryStringEncoding.Utf8);
IBuffer saltBuffer = CryptographicBuffer.ConvertStringToBinary(salt, BinaryStringEncoding.Utf16LE);
IBuffer cipherBuffer = CryptographicBuffer.CreateFromByteArray(encryptedData);
// Derive key material for password size 32 bytes for AES256 algorithm
KeyDerivationAlgorithmProvider keyDerivationProvider = Windows.Security.Cryptography.Core.KeyDerivationAlgorithmProvider.OpenAlgorithm("PBKDF2_SHA1");
// using salt and 1000 iterations
KeyDerivationParameters pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(saltBuffer, 1000);
// create a key based on original key and derivation parmaters
CryptographicKey keyOriginal = keyDerivationProvider.CreateKey(pwBuffer);
IBuffer keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms, 32);
CryptographicKey derivedPwKey = keyDerivationProvider.CreateKey(pwBuffer);
// derive buffer to be used for encryption salt from derived password key
IBuffer saltMaterial = CryptographicEngine.DeriveKeyMaterial(derivedPwKey, pbkdf2Parms, 16);
// display the keys – because KeyDerivationProvider always gets cleared after each use, they are very similar unforunately
string keyMaterialString = CryptographicBuffer.EncodeToBase64String(keyMaterial);
string saltMaterialString = CryptographicBuffer.EncodeToBase64String(saltMaterial);
SymmetricKeyAlgorithmProvider symProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm("AES_CBC_PKCS7");
// create symmetric key from derived password material
CryptographicKey symmKey = symProvider.CreateSymmetricKey(keyMaterial);
// encrypt data buffer using symmetric key and derived salt material
IBuffer resultBuffer = CryptographicEngine.Decrypt(symmKey, cipherBuffer, saltMaterial);
string result = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf16LE, resultBuffer);
return result;
public static string AES_Encrypt(string input, string pass)
SymmetricKeyAlgorithmProvider SAP = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7);
CryptographicKey AES;
HashAlgorithmProvider HAP = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
CryptographicHash Hash_AES = HAP.CreateHash();
string encrypted = "";
try
byte[] hash = new byte[32];
Hash_AES.Append(CryptographicBuffer.CreateFromByteArray(System.Text.Encoding.UTF8.GetBytes(pass)));
byte[] temp;
CryptographicBuffer.CopyToByteArray(Hash_AES.GetValueAndReset(), out temp);
Array.Copy(temp, 0, hash, 0, 16);
Array.Copy(temp, 0, hash, 15, 16);
AES = SAP.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(hash));
IBuffer Buffer = CryptographicBuffer.CreateFromByteArray(System.Text.Encoding.UTF8.GetBytes(input));
encrypted = CryptographicBuffer.EncodeToBase64String(CryptographicEngine.Encrypt(AES, Buffer, null));
return encrypted;
catch (Exception ex)
return null;
public static string AES_Decrypt(string input, string pass)
SymmetricKeyAlgorithmProvider SAP = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7);
CryptographicKey AES;
HashAlgorithmProvider HAP = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
CryptographicHash Hash_AES = HAP.CreateHash();
string decrypted = "";
try
byte[] hash = new byte[32];
Hash_AES.Append(CryptographicBuffer.CreateFromByteArray(System.Text.Encoding.UTF8.GetBytes(pass)));
byte[] temp;
CryptographicBuffer.CopyToByteArray(Hash_AES.GetValueAndReset(), out temp);
Array.Copy(temp, 0, hash, 0, 16);
Array.Copy(temp, 0, hash, 15, 16);
AES = SAP.CreateSymmetricKey(CryptographicBuffer.CreateFromByteArray(hash));
IBuffer Buffer = CryptographicBuffer.DecodeFromBase64String(input);
byte[] Decrypted;
CryptographicBuffer.CopyToByteArray(CryptographicEngine.Decrypt(AES, Buffer, null), out Decrypted);
decrypted = System.Text.Encoding.UTF8.GetString(Decrypted, 0, Decrypted.Length);
return decrypted;
catch (Exception ex)
return null;
Both methods shown above are not giving the same result.
I would require the following scenario :
Plain Text : "login@123"
Key : "0123456789abcdef"
IV : "fedcba9876543210"
Hex : 356F65678C82C137BDBB2A2C8F824A68
Encrypted Text : 5oegåÇ¡7Ωª*,èÇJh
Request you to please suggest alternative to obtain the same AES Encryption using a Key and IV in Windows Phone.
Thanks in advance.
Regards,
Vinay D

Hi,
The encryption and decryption in : http://dotnetspeak.com/2011/11/encrypting-and-decrypting-data-in-winrt-2 is
not giving me the desired result.
I would require the following scenario :
Plain Text : "login@123"
Key : "0123456789abcdef"
IV : "fedcba9876543210"
Encrypted Text : 5oegåÇ¡7Ωª*,èÇJh
But what i am getting from the above link is : 
I would require the following scenario :
Plain Text : "login@123"
Key : "0123456789abcdef"
IV : "fedcba9876543210"
Encrypted Text : NW9lZ4yCwTe9uyosj4JKaA==
As u can see the encrypted string is not the same and hence i would get a different decrypt string on the server.
I cannot change the server as it is in production and working with Android and IOS.
Regards,
Vinay D

Similar Messages

  • HP All-in-One Printer Remote App For Windows Phone 8.1 Troublesho​ot

    Dear HP,
    Device                Nokia Lumia 520
    OS                        Windows Phone 8.1
    Printer                HP Officejet Pro 8600 All in One Printer
    I have installed HP All-in-One Printer Remote on my smartphone as well as on my PC having Microsoft Windows 8.1. The PC app is running 
    fine but on my smartphone, app can't find my HP Wireless printer. All Devices(PC, Smartphone, Printer) are connected to same wireless LAN Network.
    Regards
    Sahyog Vishwakarma
    Mob.: +91-7206369455
    Yamuna Nagar
    Haryana

    Hi,
    The app for Windows phone is a BETA version. In my case (also a Nokia) it can find my printer but when sending something to printer, printer won't print. Again, it's only a BETA version.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Preview for Developers update for Windows Phone 8.1.1

    Start your phone updates
    Microsoft has just pushed out Windows Phone 8.1.1 for those participating in the Preview Developer Program.
    It's believed to fix the following issues:
    lingering issues with those not getting the Lumia Cyan firmware
    errors in installing
    and even a fix for HTC users
    Source: Microsoft rolling out Preview for Developers update for Windows Phone 8.1.1 | Windows Phone Central

    primortal wrote:
    This bit is interesting from the Windows Phone Blog in regards to this update.
    Remember, while we are releasing Lumia Cyan for a large number of phones, there still may be some of you that are not offered the Cyan update, yet. However, as explained in the blog, we’ll continue to add more Lumia devices every couple of days over the coming weeks until we bring everyone up to the latest.
    Source: New Update for Windows Phone Preview for Developers
    That Text is no where to be found in that blog post. Anywhere.

  • How is SQLite used for windows phone 8.1 in Visual Studio2013

    Hi, 
           I'm developing app on Windows 8.1 currently. Can any one please help me with the steps to proceed so that I can create a database using SQLite for windows phone 8.1 through Visual Studio2013.

    Hi SwetaSinha,
    Thank you for posting in MSDN forum.
    Since this forum is to discuss: Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help
    System, and Visual Studio Editor.
    Based on your issue, if you want to know how to create a database using SQLite, I suggest you can ask this issue directly to the  SQLite official website:
    http://www.sqlite.org/support.html, maybe you will get better support.
    In addition, since the SQLite is a extension tool for the Windows Phone 8.1, so I suggest you can post this case to the SQLite for Windows Phone 8.1:https://visualstudiogallery.msdn.microsoft.com/5d97faf6-39e3-4048-a0bc-adde2af75d1b,
    and then click “Q AND A”, you will get better support there.
    Thanks for your understanding.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Make a flashlight App for Windows Phone 8.1 (TorchControl not supported)

    I want to develop a simple flashlight app for Windows Phone 8.1 (non Silverlight). I used the TorchControl but it returns a false when i tried to run on my Device
    Here is the code i Used
    private async void SwitchOn(object sender, RoutedEventArgs e)
    var mediaDev = new MediaCapture();
    await mediaDev.InitializeAsync();
    var videoDev = mediaDev.VideoDeviceController;
    var tc = videoDev.TorchControl;
    if (tc.Supported)
    if (tc.PowerSupported)
    tc.PowerPercent = 100;
    tc.Enabled = true;
    else
    res.Text = "not Supported";
    Is there any other way to do that..
    Thanks In Advance.
    Gopal Kandoi

    Hi Gopal,
    I would also suggest you to try the solution from this post:
    https://social.msdn.microsoft.com/Forums/en-US/329c40e7-fa9a-4a27-8347-b4a80100842e/cant-turn-on-lumia-1520-wp-81-flashlight-use-videodevicecontrollertorchcontrol?forum=wpdevelop
    Start the video capture first and then start the torch control.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • SQLite3-WinRT / SQLite3Component for Windows Phone 8.1 (HTML5 & JavaScript)

    Dear all
    I am a newbie in the developpement for Windows 8.1 and Windows Phone 8.1.
    After a few weeks reading books and watching videos to learn developping Windows Store Apps 8.1 with HTML5 and JavaScript, I have started my very first serious application as a Universal Windows Store App using visual studio 2013 community edition. I would
    like to use SQLite for persisiting the data of my application.
    I installed the necessary extensions to VS2013 both for windows 8.1 and windows phone 8.1 (SDK + SQLite extension)
    I cloned the SQLite3-WinRT projet from GitHub, and, as VS2013 asked it, run the targetting process to upgrade to Windows 8.1.
    I successfully installed and tested SQLite3-WinRT using Javascript for the WIndows 8.1 part of my project.
    But when i tried to add the SQLite3Component project as a reference to my Windows Phone 8.1 project, VS2013 complained that SQLite3Component project is an invalid reference for a windows phone project... I can understand this as the SQLite3Component project
    seems to be a windows 8 only project.
    I have been looking for a solution for two days now without success and decided therefore to post my question here: is there a SQLite3Component project targetted for WINdows Phone 8(.1)? If not, what are my alternatives for persisting potentially large amount
    of data with advanced search queries locally on a windows phone?
    Thank you for any help the comunity could give me.
    Regards
    François

    While not specifically talking about JavaScript/HTML5 this article series outlines how to use SQLite in Universal App projects:
    http://blog.tpcware.com/2014/04/universal-app-with-sqlite-part-1/
    I have already used it from C# and given that we're talking about WinRT components it should be accessible from WinJS as well. Hope it helps.

  • No Jabber client for Windows Phone 8.1

    Can you advise on when a Jabber client for Windows Phone 8.1 will be released?

    Roadmap questions cannot be addressed here, either ask in a partner forum, or reach your SE/AM for this.

  • QuickControl app for Windows Phone 8.1???

    Hello,
    I'm totally happy with my Thinkpad X240 but I would like to be able to use remote control -for instance to pause/resume VLC player when the Thinkpad is hooked up to my TV. I read that Lenovo has this great program 'QuickControl', but you obviously need an accompanying app on your smartphone.
    I can find the app for iOS and Android, but I happen to own a Windows Phone (with WP8.1)... Since I'm trying to build a 'Windows Only' life after mixed experiences with Android and OSX, I would really like the QuickControl app to be available for Windows Phone. I guess it would make sense for Lenovo -being a manufacturer of PC's- to also develop QuickControl for the Windows Phone...
    Does any of you community members know where to find this app, or if/when it will become available? Or do you know another WP app that can communicate with QuickControl installed on a Thinkpad X240?
    Any help is much appreciated. Oh, and by the way: Happy Holidays everyone!

    Nice free

  • Renderpdf for Windows Phone 8.1

    Hi,
    I am trying to build a windows phone 8.1 app in which I want to render a PDF (with possible zoomed view) and display it and also I want to generate images from that PDF. Is there any third party component for doing this task?
    Thanks in advance.

    UPDATE
    According to these links and the comments from Mitch Denny, can somebody confirm that .appx files (company apps) cannot be deployed/installed on windows phone 8.1 yet?
    http://blogs.technet.com/b/windowsintune/archive/2014/05/12/what-s-coming-next-with-windows-intune.aspx
    http://blogs.technet.com/b/windowsintune/archive/2014/04/28/availability-of-update-to-windows-intune-for-windows-phone-8-1-and-samsung-knox-standard.aspx
    I would really appreciate if someone can confirm me this, because im struggling with this since days and there is no official statement from MS.
    Thanks

  • Inking for Windows Phone 8.1 (Not Silverlight)

    Is there any way to use Inking for Windows phone 8.1 application. I am able to use it in Silverlight application for freehand drawing.
    But is there anything available to use for this purpose in WinRT?

    Hi Morichi,
    As far as I known in Windows Phone 8.1 Runtime there is no such a Inking api or control as in Windows Phone 8.1 Silverlight app. If you want to implement the inking function in Windows phone 8.1 Runtime application, please try to refer to
    the @Rob Caplan - MSFT's reply in this thread:
    http://stackoverflow.com/questions/28862500/inking-for-windows-phone-8-1-not-silverlight .
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Is Cisco VPN posible for Windows Phone 8.1

    Hello,
    Microsoft released Windows Phone 8.1 on April and it supports VPN connections.
    So I would like to ask:
    Is Cisco going to release Anyconnect Secure Mobility Client for Windows Phone 8.1?
    Maybe someone managed to make clientless connection with ASA 9.1( for example IKEv2 or SSL-VPN) ?
    Or should I abandon idea of connecting WP 8.1 with ASA?
    Thanks.

    Hi  aurimas88 ,
    Looks like AnyConnect Secure Mobility Client 2.5  is supported for windows phone , however W 8.1 mobile has not been tested by Cisco , We cannot guarantee compatibility. 
    AnyConnect Secure Mobility Client 3.0 Windows Mobile Devices Not Supported
    AnyConnect version 3.0 and later do not support Microsoft Windows Mobile or Windows Phone. However, you can continue to use the ASA to deploy the AnyConnect 2.5 or earlier client for Windows Mobile even after loading the AnyConnect 3.0 package files to the ASA for web deployment.
    AnyConnect Secure Mobility Client 2.5 Windows Mobile Devices Supported
    We designed AnyConnect 2.5 for compatibility with Windows Mobile 6.5, 6.1, 6.0 and 5.0 Professional and Classic for touch-screens only. Users have reported success with most touch-screens running these versions of Windows Mobile. However, to ensure interoperability, we guarantee compatibility only with the devices we test, as follows:
    HTC Imagio running Windows Mobile 6.5
    HTC Tilt 2 running Windows Mobile 6.5
    HTC Touch running Windows Mobile 6.0
    HTC TyTN running Windows Mobile 5.0
    Samsung Epix running Windows Mobile 6.1
    Samsung Omnia Pro 4 running Windows Mobile 6.5
    Samsung Omnia running Windows Mobile 6.1
    Samsung Saga running Windows Mobile 6.1
    Source: 
    http://www.cisco.com/c/en/us/td/docs/security/asa/compatibility/asa-vpn-compatibility.html#pgfId-181897
    Hope this helps 

  • Windows Intune support deployment for windows phone (8.1) *.appx files

    Hi
    We are trying to deploy a windows phone 8.1 appx file with intune (over sccm console). the appx file is signed with a valid symantec certificate.
    the installation of the app fails, either when we upload the file as "Required" (so pushing it automatically to the devices) or when we make the app on the company portal app available. 
    in the sccm console the deployment status says failed -> unkonwn error.
    when we use .xap file of an windows 8.0 app, it works like a charm and the xap file is signed with the same certificate.
    My question is, is there no support for publishing windows phone 8.1 appx files on Intune? Or what can it be?
    Thanks for any hints

    UPDATE
    According to these links and the comments from Mitch Denny, can somebody confirm that .appx files (company apps) cannot be deployed/installed on windows phone 8.1 yet?
    http://blogs.technet.com/b/windowsintune/archive/2014/05/12/what-s-coming-next-with-windows-intune.aspx
    http://blogs.technet.com/b/windowsintune/archive/2014/04/28/availability-of-update-to-windows-intune-for-windows-phone-8-1-and-samsung-knox-standard.aspx
    I would really appreciate if someone can confirm me this, because im struggling with this since days and there is no official statement from MS.
    Thanks

  • Will MDM for windows phone 8.0 support for windows phone 8.1

    We have successfully implemented MDM solution for windows phone 8.0 . Enrolment and polling working properly.
    Now devices will come for windows phone 8.1 .Will this existing system work for 8.1 also? Or is there any changes need to be done?

    As far as I am aware it will be ok. 8.1 just exposes additional functionality and CSP's available to be manipulated.
    I will double check on that to be 100% sure.

  • Books about MVVM, architecture, design patterns for Windows Phone 8.1

    Hi,
    I'm looking for a book or books (or other resources) that explain how to develop an app with a proper architecture. I mean what each layer (bussines layer, data layer, network access) should do and how should it look like. I'm also looking for a book about
    MVVM.
    Right now I'm struggling with how to create a layer for network communication - how to separate classes for requests and responses, how to manage requests and create some queue of requests and also to provide some way to cancel them when they are no longer
    needed, how to work with servers that use some level of security (cookies, certificates etc.).
    Another thing is caching - how to design a short-term cache or a persistant cache (database), what technologies I can use etc.
    Last thing that I'm struggling with is also naming. How to name classes in those layers, e.g. to distinguish between classes mapping data from some ORM database, for mapping on JSON in network communication. etc.
    I hope you got the idea :)
    Thanks.

    Currently, I don't find a book about MVVM pattern for Windows Phone 8.1, but I think MSDN and some blogs have some useful samples and conceptions: http://msdn.microsoft.com/en-us/library/windows/apps/jj883732.aspx
    http://channel9.msdn.com/Series/Windows-Phone-8-1-Development-for-Absolute-Beginners
    And I think your question includes too much scopes, maybe you need to split it into some blocks and get help in the related forum
    Best Regards,
    Please remember to mark the replies as answers if they help

  • Simple upload image to amazon S3 winjs for windows phone 8.1?

    Hi
    Can behind simple upload image to amazon S3 winjs for windows phone 8.1?Thank

    Yes.
    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
    objects and unknown namespaces.

Maybe you are looking for

  • How can I add multiple email addresses  from spreadsheet into email?

    how can I add multiple email addresses  from spreadsheet into email?

  • Stored Procedure in NAtive SQL

    Hello All, Where to check the definition of the following stored procedure in NAtive SQL. EXEC SQL.     EXECUTE PROCEDURE "APS_PEGID_GET_IO" (                          IN  :LS_GEN_COM_PARAMS,                          OUT :LV_RC,                      

  • What is the best way to manage the large FinalCutProX files

    We are continously running out of space on our desktop with the FinalCutProX files being so large. We have moved most of the files (events & projects) to an external server and working off the single video projects from our desktop. How are you worki

  • Plz help!! array of object (for search)

    i've got few questions of array of object 1-how to search for a price that is greater than 300 in the array of object and how to list all of them? 2- how to search for the smallest price in the array of object, and how to list? can anyone provde a ja

  • Clone stamp - fixed position sampling?

    It seems there is a way to fix the sampling to a fixed position on the alt-click so that the cross does not move even though you are moving the brush. Is that correct and if so, how?