Getting certificate from XMLSignature in Java -
i'm trying certificate out of xmlsignature, it's crl distributionpoint , verify if it's valid.
i have digital document , signature file name, , that's how xmlsignature:
zipfile zipfile = new zipfile(datafactory.getdatareader().getfileadoc(adocfilename)); zipentry entry = zipfile.getentry(signaturefilename); documentbuilderfactory dbf = documentbuilderfactory.newinstance(); dbf.setnamespaceaware(true); document doc = dbf.newdocumentbuilder().parse(zipfile.getinputstream(entry)); nodelist nl = doc.getelementsbytagnamens(xmlsignature.xmlns, "signature"); if (nl.getlength() == 0) { throw new exception("cannot find signature element"); } xmlsignaturefactory fac = xmlsignaturefactory.getinstance("dom"); domvalidatecontext valcontext = new domvalidatecontext(new x509keyselector(), nl.item(0)); zipfileuridereferencer dereferencer = new zipfileuridereferencer(zipfile); valcontext.seturidereferencer(dereferencer); xmlsignature signature = fac.unmarshalxmlsignature(valcontext);
now, how certificate or x509certificate?
i have tried getting < x509certificate > part:
nodelist sertificatenodelist = doc.getelementsbytagname("x509certificate"); if (sertificatenodelist.getlength() == 0) { throw new exception("cannot find x509certificate element"); } string certpart = sertificatenodelist.item(0).getfirstchild().getnodevalue(); system.out.println(certpart); inputstream = new bytearrayinputstream(certpart.getbytes()); certificatefactory cf = certificatefactory.getinstance("x.509"); certificate cert = cf.generatecertificate(is);
but gives me:
java.security.cert.certificateparsingexception: invalid der-encoded certificate data
maybe need somehow encode inputstream is?
the signature.xml contains:
<x509certificate> miikvtccct2gawibagioy7w3f/j6vnsaaqainyywdqyjkozihvcnaqefbqawgbsxczajbgnvbayt akxumuawpgydvqqkezdhexzlbnrvanugcmvnaxn0cm8gdgfybnliysbwcmlliexsifzstsatigku ... fwxieii3ktgsvpyz1/c7qhlv0srmacm/+qhupswh+l5yicjbxqbd4bu2q9sow7qshkrnrjowsonk rw/cd4gwzdpte3v42qj6szazsjdrgtfagbg3 </x509certificate>
thanks!
inputstream = new bytearrayinputstream(**unbase64**(certpart));
hi brutus, unbase64 x509certificate value
Comments
Post a Comment