Retrieving All Certificates from PKI Credentials

To retrieve all certificates from PKI credentials, complete the following steps:

  1. Retrieve all the certificates that are bound to a specified wallet:

    Copy
    WalletId walletId = walletMgr. getBoundWalletFromUser(userId);
    Criteria[] criterias = {
    new Criteria(CCMConstants.CRITERIA_CRED_TYPE, CCMConstants.CRITERIA_COMPARISON_EQUAL, CCMConstants.CRED_ID_TYPE_PKI),
    new Criteria(CCMConstants.
    CRITERIA_CRED_PARENT_WALLET, CCMConstants.CRITERIA_COMPARISON_EQUAL,
    walletId.getId())
    };
  2. Find the actions that meet the supplied criteria:

    Copy
    CredentialId[] credIds = credMgr. findCredentialIds(criterias, maxItems);
    Credential[] creds = credMgr.getCredentials(credIds);
  3. Print all the certificates in each PKI credential:

    Copy
    for(int i=0; i< elements.length; i++) { CredentialElement[] elements = creds[i].
    getCredentialElements();
    System.out.println("-----BEGIN CERTIFICATE-----"); System.out.println(elements[0].getValue()); System.out.println("-----END CERTIFICATE-----");
    }