Your key is part of the public key module, whose length is 128. Consider a standard key exported from C # code to the metro:
using System.Runtime.InteropServices.WindowsRuntime; CryptographicKey standardKeyPair = provider.CreateKeyPair(1024); byte[] standardKey = standardKeyPair.ExportPublicKey(CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey).ToArray();
you can see the byte length [] of standardKey is 140, which has a prefix of 7 bits and 5 bits of tail. I do not know the reason, but I copied an additional 12 bits to the known key, it works. Hope this helps you:
public static IBuffer RsaEncrypt(this IBuffer dataToEncrypt, string publicKeyN) { AsymmetricKeyAlgorithmProvider provider = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1); CryptographicKey standardKeyPair = provider.CreateKeyPair(1024); byte[] standardKey = standardKeyPair.ExportPublicKey(CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey).ToArray(); var data_n = CryptographicBuffer.DecodeFromBase64String(publicKeyN).ToArray(); Array.Copy(data_n, 0, standardKey, 7, data_n.Length); var key = provider.ImportPublicKey(standardKey.AsBuffer(), CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey); var result = CryptographicEngine.Encrypt(key, dataToEncrypt, null); return result; }
source share