Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Separate Key Pair using PCLCrypto (Windows.Security.Cryptography)

BrunoBarcellosBrunoBarcellos USMember
edited December 2016 in Xamarin.Forms

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()'.

:) thanks already


Sign In or Register to comment.