让每一个算法消息摘要可以使用吗? [英] Get every algorithm MessageDigest can use?

查看:98
本文介绍了让每一个算法消息摘要可以使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

消息摘要需要一个字符串,当你即将哈希使用哪种算法。 我用了一些code这里积聚我的Andr​​oid设备上的220算法,而大名单。用它们作为一种算法,消息摘要和极少数人我迭代通过所有这些实际产生的哈希值。

MessageDigest takes a string for what algorithm to use when you're about to hash. I've used some of the code here to accumulate a rather large list of 220 "algorithms" on my android device. I iterated through all of them using them as an algorithm in MessageDigest and very few of them actually produce a hash.

我怎样才能在运行时,确定散列消息摘要将产生一个输出,但不尝试每一个?

How can I, at runtime, determine what hashes MessageDigest will produce an output for without trying every one?

推荐答案

列出的服务,然后调用的getType()方法。如果是消息摘要,那么这是一个散列算法。是这样的:

List the Services of each provider, then call the getType() method. If it is MessageDigest, then this is a hash algorithm. Something like:

Provider[] providers = Security.getProviders();
for (Provider p : providers) {
  String providerStr = String.format("%s/%s/%f\n", p.getName(),
                    p.getInfo(), p.getVersion());
  Set<Service> services = p.getServices();
  for (Service s : services) {
    if ("MessageDigest".equals(s.getType())) {
       System.out.printf("\t%s/%s/%s", s.getType(),
                            s.getAlgorithm(), s.getClassName());
    }
  }
}

这篇关于让每一个算法消息摘要可以使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆