How to ImportKeyPair using a Certificate in UWP?

2

I have a .p12 file and I want to use it to sign Data. This is my code:

public static async Task<String> Sign(String Message)
    {
        StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
        var CerFile = await appInstalledFolder.GetFileAsync(@"Assets\Certificates\RAS_pkcs12.p12");
        var CerBuffer = await FileIO.ReadBufferAsync(CerFile);
        string CerData = CryptographicBuffer.EncodeToBase64String(CerBuffer);

        await  CertificateEnrollmentManager.ImportPfxDataAsync
            (CerData, "123456789", 
            ExportOption.NotExportable,
            KeyProtectionLevel.NoConsent,
            InstallOptions.None,
            "RASKey");

        var Certificate = (await CertificateStores.FindAllAsync(new CertificateQuery() { FriendlyName = "RASKey" })).Single();
        AsymmetricKeyAlgorithmProvider Asym = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);

//Success get Certificate info

        var CerBlob = Certificate.GetCertificateBlob();

        var Key = Asym.ImportKeyPair(CerBlob); //It is error here
        var SignData = CryptographicEngine.Sign(Key, CryptographicBuffer.ConvertStringToBinary(Message, BinaryStringEncoding.Utf8));
        return CryptographicBuffer.EncodeToBase64String(SignData);
    }

And I get this error:

Exception from HRESULT: 0x80092002

Thank you

c#
certificate
uwp
asked on Stack Overflow Jun 14, 2016 by Dute • edited Jun 14, 2016 by Kayathiri

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0