Ok, I know this question is going to be a bit weird... but here goes:
I have an existing WPF application which uses AES encryption. I am currently developing a UWP version for Windows 10 and also Windows Phone. While developing the UWP app, I made some improvements to the encryption process and I actually prefer the CryptographicBuffer
over the .NET version.
Now I have a problem...
I'd like for users of the WPF application to upgrade their documents to the newer encryption, so that these documents can be shared between the Desktop version, and the UWP app version.
I created a class library that contains the encryption code, and it is referenced by the UWP app. But I tried in many ways to get my WPF app to reference the same library... to no avail. Which I understand.
So, is there ANY possible way to somehow get my WPF application to use the CryptographicBuffer? If there is no conceivable way to accomplish this, I would somehow need to get the same encryption in WPF using the .NET classes. One problem I know I am facing
is I'm not sure what the equivalent process would be to derive the encryption key.
In my UWP app, I am using the Pbkdf2Sha512 key derivation provider, but know of no comparable provider in .NET for my WPF app.
Here is the UWP app KeyDerivation code:
/// <summary>
/// iteration count for deriving key material
/// </summary>
private const int KEY_DERIVATION_ITERATION = 147592;
/// <summary>
/// Gets the encryption key material for a password
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
private static IBuffer GetEncryptionKeyMaterial(string password, IBuffer saltBuffer)
{
//get a password buffer
var pwBuffer = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
//create provider
var keyDerivationProvider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha512);
//create a key based on original key and derivation parmaters
var keyOriginal = keyDerivationProvider.CreateKey(pwBuffer);
//using salt and specified iterations
var pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(saltBuffer, KEY_DERIVATION_ITERATION);
//derive new key
var keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms, 32);
//return encryption key
return keyMaterial;
}
And the revevant encryption code:
//get key from our random salt
var keyMaterial = GetEncryptionKeyMaterial(password, saltBuffer);
//create a key for encrypting
var symProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
var symKey = symProvider.CreateSymmetricKey(keyMaterial);
//encrypt the plain text with key and salt material
var cypherBuffer = CryptographicEngine.Encrypt(symKey, dataBuffer, ivBuffer);
What would be my best option for getting the same encryption to work on both UWP app and my WPF app? Note: I want to avoid using third party encryption libraries, but may consider it if no other viable option exists.
Thanks
Neptune Century