Code example for X500Principal

Methods: equalsgetEncoded

0
    public static void main(String[] args) {
 
        try { 
 
            // create 2 different X500Principals 
            X500Principal p = new X500Principal("o=sun, cn=duke");
            X500Principal p2 = new X500Principal("o=sun, cn=dukette");
 
            // get the encoded bytes for the 2 principals 
            byte[] encoded = p.getEncoded();
            byte[] encoded2 = p2.getEncoded();
 
            // create a ByteArrayInputStream with the 
            // encodings from the 2 principals 
            byte[] all = new byte[encoded.length + encoded2.length];
            System.arraycopy(encoded, 0, all, 0, encoded.length);
            System.arraycopy(encoded2, 0, all, encoded.length, encoded2.length);
            ByteArrayInputStream bais = new ByteArrayInputStream(all);
 
            // create 2 new X500Principals from the ByteArrayInputStream 
            X500Principal pp = new X500Principal(bais);
            X500Principal pp2 = new X500Principal(bais);
 
            // sanity check the 2 new principals 
            if (p.equals(pp) && p2.equals(pp2) && !pp.equals(pp2)) {
                System.out.println("Test 1 passed");
            } else { 
                throw new SecurityException("Test 1 failed");
            } 
 
Connect your IDE to all the code out there  Get Codota for Java