Code example for X500Principal

0
        Calendar notBefore = Calendar.getInstance();
        Calendar notAfter = Calendar.getInstance();
        notAfter.add(1, Calendar.YEAR);
        KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx)
                .setAlias(alais)
                .setSubject( 
                        new X500Principal(String.format("CN=%s, OU=%s", alais,
                                ctx.getPackageName())))
                .setSerialNumber(BigInteger.ONE).setStartDate(notBefore.getTime())
                .setEndDate(notAfter.getTime()).build();
 
        KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA",
                "AndroidKeyStore"); 
        kpGenerator.initialize(spec);
        KeyPair kp = kpGenerator.generateKeyPair();
 
        return kp;
    } 
 
    public static String signRsaPss(String keyAlias, String toSign) {
        try {