Skip to content

Commit

Permalink
Merge pull request #1265 from lprimak/shiro-parse-unsalted
Browse files Browse the repository at this point in the history
[#1022] bugfix(crypto): Shiro 1 hash parser now supports unsalted passwords
  • Loading branch information
lprimak authored Jan 4, 2024
2 parents 78fca2f + ab7d4ba commit 6e59168
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ public Hash parse(final String formatted) {
String iterationsString = parts[i--];

byte[] digest = Base64.decode(digestBase64);
ByteSource salt = null;
ByteSource salt;

if (StringUtils.hasLength(saltBase64)) {
byte[] saltBytes = Base64.decode(saltBase64);
salt = ByteSource.Util.bytes(saltBytes);
} else {
salt = ByteSource.Util.bytes(new byte[0]);
}

int iterations;
Expand All @@ -174,9 +176,7 @@ public Hash parse(final String formatted) {

SimpleHash hash = new SimpleHash(algorithmName);
hash.setBytes(digest);
if (salt != null) {
hash.setSalt(salt);
}
hash.setSalt(salt);
hash.setIterations(iterations);

return hash;
Expand Down

0 comments on commit 6e59168

Please sign in to comment.