File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
java/ql/test/query-tests/security/CWE-327/semmle/tests Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,16 @@ void hashing() throws NoSuchAlgorithmException, IOException {
1414 // BAD: Using a weak hashing algorithm
1515 MessageDigest bad = MessageDigest .getInstance (props .getProperty ("hashAlg1" ));
1616
17+ // BAD: Using a weak hashing algorithm even with a secure default
18+ MessageDigest bad2 = MessageDigest .getInstance (props .getProperty ("hashAlg1" , "SHA-256" ));
19+
1720 // GOOD: Using a strong hashing algorithm
1821 MessageDigest ok = MessageDigest .getInstance (props .getProperty ("hashAlg2" ));
22+
23+ // OK: Using a strong hashing algorithm even with a weak default
24+ MessageDigest ok2 = MessageDigest .getInstance (props .getProperty ("hashAlg2" , "MD5" ));
25+
26+ // OK: Property does not exist and default is secure
27+ MessageDigest ok3 = MessageDigest .getInstance (props .getProperty ("hashAlg3" , "SHA-256" ));
1928 }
2029}
You can’t perform that action at this time.
0 commit comments