Ash*_*pta 2 java md5 fips java-security
我已禁用 MD5 算法,使用在$JAVA_HOME/lib/security/java.security文件中添加以下内容。但我仍然能够运行使用 MD5 算法的代码。
jdk.certpath.disabledAlgorithms=MD2, MD5, SHA1 jdkCA & usage TLSServer
jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024
jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024
Run Code Online (Sandbox Code Playgroud)
但我仍然可以运行以下使用 MD5 的代码
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
public static String getMd5(String input)
{
try {
// Static getInstance method is called with hashing MD5
MessageDigest md = MessageDigest.getInstance("MD5");
// digest() method is called to calculate message digest
// of an input digest() return array of byte
byte[] messageDigest = md.digest(input.getBytes());
// Convert byte array into signum representation
BigInteger no = new BigInteger(1, messageDigest);
// Convert message digest into hex value
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}
// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
// Driver code
public static void main(String args[]) throws NoSuchAlgorithmException
{
String s = "TESTFORMD%";
System.out.println("Your HashCode Generated by MD5 is: " + getMd5(s));
}
}
Run Code Online (Sandbox Code Playgroud)
配置的安全策略$JAVA_HOME/lib/security/java.security会影响JVM如何处理安全相关功能;它与您在代码中明确(尝试)使用的算法无关。
例如:
jdk.jar.disabledAlgorithms禁用用于验证签名 jar 文件的算法jdk.certpath.disabledAlgorithms禁用用于证书的算法(也会影响密钥长度)jdk.tls.disabledAlgorithms禁用用于 TLS 密码协商的算法因此,当您在安全配置中禁用 MD5 时,您实际上是在告诉 JVM 不要使用/信任 MD5 进行 jar 签名、证书和 TLS 协商。实际的 MD5 实现仍然可供您在MessageDigest.getInstance("MD5").
| 归档时间: |
|
| 查看次数: |
1526 次 |
| 最近记录: |