J3r0M3 J3r0M3 - 1 year ago 247
C# Question

cordova plugin x509store

I have to develop an app with cordova targeting mainly Windows platform.
In this app, I have to manipulate the certification store. Long story short answer, I have to do a cordova plugin (or maybe an activeX trick).
I made a windows runtime component in C#, as explained here, to use X509Store (as I need Windows).
I used visual studio 2015 to make a windows runtime component project (I tried universal windows and 8.1). It works, I can call C# methods in my .js.

But the problem is: a windows runtime component project doesn't have the namespace System.Security.Cryptography.X509Certificates. So I can't access to X509Store.

As a workaround, I made a Class library (.NetCore, .dll) which call X509Store and return strings, at least to show the certificate (json stringify). A classic class library can also access to x509store but it makes target error when I reference it in this windows runtime component project. (a portable/universal dll project doesn't have X509Store neither). My .netcore dll works, I tried it in a Console Application (.NetCore) project and it showed all my certificates. But when I call it from the cordova app (cordova app -> plugin -> runtime -> .netcore dll) it's empty (no certificate found, and the current user is undefined). I think it's because the execution context is not the same (webapp vs console app). And i don't think it's a good solution (which doesn't even work).

So, how can I access to the certification store (of the windows user) in a windows runtime component ? As I don't think it's possible with javascript.


P.S: I can provide some source code if needed


I forgot that there is an assembly conflict in the runtime project with the .netcore dll which I solved by referencing the right dll in plugin.xml file (System.Runtime.dll etc ..) as I didn't manage to solve it in visual studio

//script inside cordova, called after device ready
signatureplugin.getAllCertNames(function(a) { }, function(a) { }, 0);

var exec = require('cordova/exec');

module.exports = {
getAllCertNames: function(successCallback, errorCallback, args) {
exec(successCallback, errorCallback, "SignaturePlugin", "getAllCertNames", [args]);

module.exports = {
getAllCertNames: function(successCallback, errorCallback, args) {
var res = SignerVerifier.PluginRT.getAllCertNames();
for (var i = 0, len = res.length; i < len; i++) {

require("cordova/exec/proxy").add("SignaturePlugin", module.exports);

//windows runtime component
using CertStore;

namespace SignerVerifier
public sealed class PluginRT
public static string[] getAllCertNames()
var certStore = new StoreManager();
var res = certStore.getAllCertificates();
return res;


//.NetCore dll
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;
using System;

namespace CertStore
public class StoreManager
private X509Store store;

public StoreManager()
store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

public string[] getAllCertificates()
List<string> res = new List<string>();

var certificates = store.Certificates;
foreach (var cert in certificates)

return res.ToArray();

If i do a javascript blank app project + Windows Runtime Component project (projects from "universal", I don't have "Windows Store" and I use windows 10) then add the .netcore dll i got the conflict which lead to an exception:

System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

(in cordova I prevent this exception by referencing System.Runtime.dll, etc ..., from the nuget package NETStandard.Library.1.6.0 used in .netcore)
I must miss something. .NetCore dll doesn't seem compatible, but the windows runtime project target .NetCore

EDIT 2: (solved)

vcsjones's answer = workaround useless (and no problem from the previous edit).
BUT in anycase there is a security issue, and I have to check "Shared User Certificates" in Capabilities in the appxmanifest

Answer Source

WinRT does certificate management different from the Desktop and Core framework. For WinRT, you would use the Windows.Security namespace.

You can open and manage the certificate store using the Windows.Security.Cryptography.Certificates.CertificateStore class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download