Retrieving All Certificates from PKI Credentials
To retrieve all certificates from PKI credentials, complete the following steps:
-
Retrieve all the certificates that are bound to a specified wallet:
CopyWalletId 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())
}; -
Find the actions that meet the supplied criteria:
CopyCredentialId[] credIds = credMgr. findCredentialIds(criterias, maxItems);
Credential[] creds = credMgr.getCredentials(credIds); -
Print all the certificates in each PKI credential:
Copyfor(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-----");
}