General J2EE: X509Certificate encoding

  1. X509Certificate encoding (3 messages)

    Hello all,

    I have an web application that conect with https and request a client certification.
    i get the client certificate from the request:

        X509Certificate[] certs = (X509Certificate[])request.getAttribute("javax.servlet.request.X509Certificate");
        X509Certificate cert = certs[0];
        String dn = cert.getSubjectDN().getName();

    this string: "CÚsar Fernßndez"

    i want the string that appears well in the Internet Explorer is: "César Fernández" (name with accents)

    i intent:
        byte[] value = dn.getBytes();
        String dnS = new String(value, "ISO-8859-1");

    but it don't works.

    thanks in advance,

    Threaded Messages (3)

  2. X509Certificate encoding[ Go to top ]

    Don't know if if works but try this:
    X509Certificate[] certs = (X509Certificate[])request.getAttribute("javax.servlet.request.X509Certificate");
        X509Certificate cert = certs[0];
    X500Principal principal = (X500Principal) cert.getSubjectDN();
    String dn = principal.getName(X500Principal.CANONICAL);
    String dn = principal.getName(X500Principal.RFC1779);

    Best regards, Mircea
  3. Hello,

    it thinks that don't works, thanks anyway.

  4. Small advice[ Go to top ]

    I am not good in encryption but I got this example
    from the sun security forum and this example works prity good.

    import java.security.Security;
    import java.security.Key;
    import java.security.KeyPair;
    import java.security.KeyFactory;
    import java.security.KeyPairGenerator;
    import java.security.SecureRandom;
    import sun.misc.BASE64Encoder;
    import java.security.spec.X509EncodedKeySpec;
    import org.bouncycastle.util.encoders.Base64;
    import java.io.*;
          //Restore Keys from the File
            KeyFactory kf = java.security.KeyFactory.getInstance("RSA","BC");
            BufferedReader br = new BufferedReader(new FileReader(fileName));
            StringBuffer keyBase64 = new StringBuffer();
            String line = br.readLine ();
            Key key = null;
            while(line != null)
               keyBase64.append (line);
               line = br.readLine ();
            byte [] bytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());