2

I am getting certificates from the keystore based on alias name using the below code,

    KeyStore keyStore = KeyStore.getInstance("Windows-MY");

    Enumeration aliasesEnum = keyStore.aliases();

    while(aliasesEnum.hasMoreElements())
    {
       aAliasName = (String)aliasesEnum.nextElement();  
       X509Certificate certificate = (X509Certificate)keyStore.getCertificate(aAliasName);
    }

Is there any way to get aliases from the current token instead of getting from keystore?.

Thanks in advance.

2
  • If you have another problem now, then create a new question. It is bad practice to change your question after it has been answered, because then the answers don't match the question anymore. Commented Mar 29, 2016 at 12:57
  • @Vijaya, as Omikron pointed out, please revert your question and open a new question for your new issue. So the answer(s) below would match the question, and people visiting this question in the future know what would solve their problem. You can accept the answer which solved your issue, thus closing this question. Commented Mar 29, 2016 at 14:27

2 Answers 2

1

It is not possible to get a particular certificate other than knowing the alias.

The best practice would be to have unique alias in your use case, so you will know which certificate you are getting.

If you are storing the Certificate through the KeyStore api, you can do a containsAlias(alias) to see if the alias already exists before you save.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks you for your reply. i fixed the issue by following this link joinup.ec.europa.eu/software/sd-dss/issue/….
Now i am having another problem can you please check updated question.
0

Normally alias names are unique. This is a problem specific to MSCAPI keystore. There are several bug reports (some of them very old) regarding this issue:

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=2162058

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6483657

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8058544

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6672015

Follow the last link, it contains a workaround. You basically have to modify the alias names via reflection API into something unique (see code in link). Not exactly a clean solution, but unfortunately the only way.

3 Comments

Thanks you for your reply. i fixed the issue by following this link joinup.ec.europa.eu/software/sd-dss/issue/….
I think this is same as last link you have provided.
Now i am having another problem can you please check updated question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.