MessageDigest.getInstance(“SHA") 返回什么特定的哈希算法?

2022-01-10 00:00:00 cryptography java undefined-behavior

MessageDigest.getInstance("SHA") 似乎工作并给了我一个 MessageDigest,但我不知道它给了我什么算法.

MessageDigest.getInstance("SHA") seems to work and gives me a MessageDigest, but I can't tell what algorithm it's giving me.

是 SHA-1 还是 SHA-0 还是 ..?

Is it SHA-1 or SHA-0 or ..?

我对我的机器上发生的事情不感兴趣.我想知道它是否会为所有有效的 Java 实现返回 sha0 或 sha1(或者它是未定义的).

I'm not interested in what happens on my machine. I want to know whether it will return sha0 or sha1 for all valid implementations of Java (or it's undefined).

推荐答案

JCE 规范 列出了实现应该支持的标准名称.指定了SHA-1",以及 SHA-256、SHA-384 和 SHA-512.SHA"、SHA-0"和SHA-2"不是标准名称,因此可能根本不受支持.您不能保证SHA"会返回什么,如果有的话,因为它不在标准中.

The JCE Specification lists standard names that an implementation is expected to support. "SHA-1" is specified, as are SHA-256, SHA-384, and SHA-512. "SHA", "SHA-0" and SHA-2" are not standard names and therefore may not be supported at all. You cannot guarantee what "SHA" will return, if anything at all, because it is not in the standard.

相关文章