I want to separate the key pair using PCLCrypto, but 'CryptographicEngine.Encrypt' and 'CryptographicEngine.Decrypt' expects a 'ICryptographicKey' that the description says : "Represents a symmetric key or an asymmetric key pair", that means it cannot be a just the public or just the private asymetric key ?
Because I need the server to have one and the user the other, how do I separate them into a 'ICryptographicKey' type?
That's what I have working :
using PCLCrypto; using static PCLCrypto.WinRTCrypto; //... ICryptographicKey keyPair = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaPkcs1).CreateKeyPair(512); var encrypted = CryptographicEngine.Encrypt(keyPair, Encoding.UTF8.GetBytes("ANYTEXT")); var decrypted = CryptographicEngine.Decrypt(keyPair, encrypted); string = Encoding.UTF8.GetString(decrypted, 0, decrypted.Length);
FAILED to separate the private key like that, throws an Exception saying private key is missing :
byte byteKeyPubl = keyPair.ExportPublicKey(); ICryptographicKey keyPubl = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaPkcs1).ImportPublicKey(byteKeyPubl); //then var decrypted = CryptographicEngine.Decrypt(keyPubl, encrypted);
Besides that i'd also need to separate the private key, that doesn't even have a function like '.ExportPublicKey()'.