Detecting whether an algorithm is supported without creating one?

Peter Levart peter.levart at gmail.com
Sat Dec 13 21:12:37 UTC 2014


On 12/12/2014 02:20 PM, Sean Mullan wrote:
> On 12/12/2014 12:04 AM, Bernd Eckenfels wrote:
>> Just get it and throw it away, it is easier than iterating the 
>> algorithms of the providers.
>
> Yes, probably. But as you note, the other way is to iterate over the 
> Providers returned by Security.getProviders(), and call 
> p.getService("MessageDigest", "SHA-256") on each ...
>

Even simpler:

java.security.Security.getAlgorithms("MessageDigest").contains("SHA-256")

Regards, Peter


> --Sean
>
>>
>>
>>> Am 12.12.2014 um 05:02 schrieb Weijun Wang <weijun.wang at oracle.com>:
>>>
>>> I'd like to check if "SHA-256" is supported without calling 
>>> MessageDigest.getInstance("SHA-256"). Does such a method exist?
>>>
>>> My case is a multi-thread digestor like this:
>>>
>>> class Digestor {
>>>    Digestor(String alg) throws NSAE;
>>>    @ThreadSafe byte[] digest(byte[]) throws Nothing;
>>> }
>>>
>>> So a Digestor is created and multiple threads can call the digest() 
>>> method. I would be glad if the constructor can throw an NSAE but not 
>>> creating a MessageDigest object because I don't know how to safely 
>>> use it inside digest().
>>>
>>> Thanks
>>> Max

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/security-dev/attachments/20141213/d213cfb5/attachment.html>


More information about the security-dev mailing list