none
WIN8 OR WP8.1 RSA加解密问题 RRS feed

  • 问题

  • WIN8 OR WP8.1 RSA加解密问题


    服务器端返回的公钥与私钥是XML格式的如下:

     static private readonly string xmlPrivateKey = "<RSAKeyValue><Modulus>3ygUPg5AyhjXDexXcCqWYg8Z68G6DA.......Mk=</Modulus><Exponent>AQAB</Exponent><P>9vH.................Q==</P><Q>51........Q==</Q><DP>CIAq..........UQtHyOrglIsOHwOrDQgQ==</DP><DQ>iCq................5bwkRYQ==</DQ><InverseQ>ML.............HIGTJGvvH1G6/C8HU4ZPaNsoyuXA==</InverseQ><D>GwW/bcRMFCzt3cHA1.............EB/af+dLk7z................AE=</D></RSAKeyValue>";

    static private readonly string xmlPublicKey = "<RSAKeyValue><Modulus>3ygUP....................7imMk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

    但是我怎么样才能把密钥转换成ImportPublicKey所需要的IBUFFER类型????????

                    IBuffer keyBuffer = 怎么将XML格式密钥转换成此类型;

                    AsymmetricKeyAlgorithmProvider asym = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);
                    CryptographicKey key = asym.ImportPublicKey(keyBuffer, CryptographicPublicKeyBlobType.X509SubjectPublicKeyInfo);

                    IBuffer plainBuffer = CryptographicBuffer.DecodeFromBase64String(toEncrypt);
                    IBuffer encryptedBuffer = CryptographicEngine.Encrypt(key, plainBuffer, null);

                    string Encryptstr = CryptographicBuffer.EncodeToBase64String(encryptedBuffer);

    另外,怎么解密数据?????

    网上给出来的例子全是产生的随机密码,所以特别困惑,求实现代码。
    2014年12月24日 9:46

答案