Skip to content

Commit 88c3623

Browse files
committed
Refactor OpenBSDBcrypt
1 parent eba77e9 commit 88c3623

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

‎core/src/main/java/org/bouncycastle/crypto/generators/OpenBSDBCrypt.java‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,12 @@ else if (salt.length != 16)
185185

186186
// 0 termination:
187187

188-
byte[] tmp = new byte[psw.length >= 72 ? 72 : psw.length + 1];
189-
190-
if (tmp.length > psw.length)
191-
{
192-
System.arraycopy(psw, 0, tmp, 0, psw.length);
193-
}
194-
else
195-
{
196-
System.arraycopy(psw, 0, tmp, 0, tmp.length);
197-
}
198-
199-
Arrays.fill(psw, (byte)0);
188+
int tmpLen = Math.min(BCrypt.MAX_PASSWORD_BYTES, psw.length + 1);
189+
byte[] tmp = Arrays.copyOf(psw, tmpLen);
190+
Arrays.clear(psw);
200191

201192
String rv = createBcryptString(version, tmp, salt, cost);
202-
203-
Arrays.fill(tmp, (byte)0);
204-
193+
Arrays.clear(tmp);
205194
return rv;
206195
}
207196

0 commit comments

Comments
 (0)