Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help validating an X509 certificate on an XML file.

843811Jan 20 2008 — edited Jan 20 2008
I'm trying to validate an X509 certificate but I keep getting "No key found!" and "cannot find validation key" errors.
I generate the certificate and put it in a keystore with the following code:
//Es genera la parella de claus i el certificat X.509
        CertAndKeyGen claus = new sun.security.x509.CertAndKeyGen("RSA", "MD5WithRSA" );
        X500Name x500Name = new sun.security.x509.X500Name(CN,OU,O,L,ST,C);
        claus.generate( 512 );
        X509Certificate[] cadena = new X509Certificate[1];
        cadena[0] = claus.getSelfCertificate(x500Name, 24*60*60);

        //Es crea el KeyStore per guardar les claus
        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(null, null);
        ks.setKeyEntry("Alias", claus.getPrivateKey(), "ContrasenyaPrivada".toCharArray(), cadena);
        
        //Es guarda el KeyStore a un fitxer amb extensi� .ks
        FileOutputStream fos = new FileOutputStream("fitxerclaus.ks");
        ks.store(fos, "ContrasenyaFitxer".toCharArray());
        fos.close();
But the certificate format seems to be correct since I've also tried generating an X509 certificate with KeyTool and the validation still fails.
I don't know wether this is due to the X509KeySelector I'm using (taken from http://java.sun.com/developer/technicalArticles/xml/dig_signature_api/index.html) or because of the format of my XML file. I've even created a new project copying the exact same code from the mentioned link and generating the XML file with this code
	// Create the Document that will hold the resulting XMLSignature
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	dbf.setNamespaceAware(true); // must be set
	Document doc = dbf.newDocumentBuilder().newDocument();
(I use JDOM and then convert it to DOM) but validation still doesn't work. I've spent 2 days trying to figure out how to solve this problem but I can't seem to do it so if anyone can help me it would be be much appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2008
Added on Jan 20 2008
2 comments
821 views