locked
Content encryption at (windows 8 & windows phone ) app side and decryption at service side (WCF)

    General discussion

  • i have one windows 8 ,one windows phone app and a WCF service to fetch the data to the apps. in that i have one requirement that in the app i need to encrypt some data and send it to the service and at service side i need to decrypt the data and use. can anyone please suggest me which encryption & decryption algorithm is suitable to do encrypt and decrypt in both the sides.

    thanks for your ideas in advance.


    suresh

    Tuesday, April 8, 2014 2:33 PM

All replies

  • Hi,

    You can enable RSA cryptography between a .Net app (actually a WCF service hosted in Azure) and WinRT app.

    Winrt:

    String str = "String To Encrypt";
    IBuffer buf = CryptographicBuffer.ConvertStringToBinary(str,BinaryStringEncoding.Utf16BE);
    String AsymmetricAlgName = Windows.Security.Cryptography.Core.AsymmetricAlgorithmNames.RsaPkcs1;
    AsymmetricKeyAlgorithmProvider asym = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgName);
    CryptographicKey key = asym.CreateKeyPair(512);
    IBuffer enc = CryptographicEngine.Encrypt(key, buf, null);
    byte[] encryptedbyteArr;
    CryptographicBuffer.CopyToByteArray(enc, out encryptedbyteArr);
    String encryptedBase64Str = Convert.ToBase64String(encryptedbyteArr);
    
    
    //Export the private Key in WinCapi format
    
    byte[] privatekeyBytes;
    CryptographicBuffer.CopyToByteArray(key.Export(CryptographicPrivateKeyBlobType.Capi1PrivateKey), out privatekeyBytes);
    String privatekeyBase64 = Convert.ToBase64String(privatekeyBytes);
    

    .Net app

    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    String privateKey64 = "BwIAAACkAABSU0EyAAIAAAEAAQCFrMTqMU3T14zSUM5...";
    String EncryptedString = "PbauDOjqMLD2P6WSmEw==";
    byte[] EncryptedDataBlob = Convert.FromBase64String(EncryptedString);
    byte[] privateKeyBlob = Convert.FromBase64String(privateKey64);
    byte[] decryptedBytes;
    rsa.ImportCspBlob(privateKeyBlob);
    decryptedBytes = rsa.Decrypt(EncryptedDataBlob, false);
    String decryptedString =System.Text.Encoding.BigEndianUnicode.GetString(decryptedBytes

    Please refer to the link to get more information:

    http://www.japf.fr/2013/05/rsa-cryptography-between-a-winrt-and-a-dotnet-app/

    Best Wishes!


    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. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, April 9, 2014 3:35 AM