SCryptPasswordEncoder to take default keyLength value

Fixes gh-4225
Closes gh-4231
This commit is contained in:
SendilKumar N 2017-02-27 20:44:54 +08:00 committed by Rob Winch
parent 168f4b8f70
commit c31bdb6390
2 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -163,7 +163,7 @@ public class SCryptPasswordEncoder implements PasswordEncoder {
} }
private String digest(CharSequence rawPassword, byte[] salt) { private String digest(CharSequence rawPassword, byte[] salt) {
byte[] derived = SCrypt.generate(Utf8.encode(rawPassword), salt, cpuCost, memoryCost, parallelization, 32); byte[] derived = SCrypt.generate(Utf8.encode(rawPassword), salt, cpuCost, memoryCost, parallelization, keyLength);
String params = Long String params = Long
.toString(((int) (Math.log(cpuCost) / Math.log(2)) << 16L) | memoryCost << 8 | parallelization, 16); .toString(((int) (Math.log(cpuCost) / Math.log(2)) << 16L) | memoryCost << 8 | parallelization, 16);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -65,7 +65,7 @@ public class SCryptPasswordEncoderTests {
@Test @Test
public void samePasswordWithDifferentParams() { public void samePasswordWithDifferentParams() {
SCryptPasswordEncoder oldEncoder = new SCryptPasswordEncoder(512, 8, 4, 64, 16); SCryptPasswordEncoder oldEncoder = new SCryptPasswordEncoder(16384, 8, 1, 32,64);
SCryptPasswordEncoder newEncoder = new SCryptPasswordEncoder(); SCryptPasswordEncoder newEncoder = new SCryptPasswordEncoder();
String password = "secret"; String password = "secret";