在 Java 中提供各种哈希算法(MD5、SHA1、SHA256 等)的库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6210449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Library providing various hash algorithms (MD5, SHA1, SHA256, etc) in Java?
提问by Naftuli Kay
Is there a simple library out there for Java in a Maven repository that will give me simple, one-liner hash methods for the popular hash functions such as MD5, SHA1, SHA256, and SHA512? I'd really hate to have to reinvent the wheel to do this.
在 Maven 存储库中是否有一个简单的 Java 库,它可以为我提供简单的单行哈希方法,用于流行的哈希函数,例如 MD5、SHA1、SHA256 和 SHA512?我真的不想重新发明轮子来做到这一点。
回答by user207421
It's built-in: java.security.MessageDigest
回答by Vineet Reynolds
The DigestUtilsclass of Apache Commons Codecis suitable for the purpose of simplifying the use of the MessageDigest class, which appears to be what you are attempting to use in the first place.
Apache Commons Codec的DigestUtils类适用于简化 MessageDigest 类的使用,这似乎是您首先尝试使用的。