c# - Convert FileUpload to X509Certificate2 -
how can convert uploaded file x509certificate2 variable?
i have tried using following code not working:
public bool haspublickey(fileupload file) { bool check = false; try { x509certificate2 cert = (x509certificate2)file.postedfile.inputstream; } catch(exception) { check = false; } }
if uploaded file valid certificate should have @ constructor or import method in x509certificate2 class.
you'll see need this:
var filelength = file.postedfile.contentlength; var certdata = new byte[filelength]; file.filecontent.read(certdata, 0, filelength); var cert = new x509certificate2(certdata);
(code not verified it, or similar, should work).
Comments
Post a Comment