Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 436de6b

Browse files
authored
Merge pull request #14 from genexuslabs/issue#82459
Fix hexa salt decoding
2 parents 84ffbb6 + b520427 commit 436de6b

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

GeneXusCryptography/src/main/java/com/genexus/cryptography/passwordDerivation/PasswordDerivation.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import com.genexus.cryptography.commons.PasswordDerivationObject;
1212
import com.genexus.securityapicommons.config.EncodingUtil;
13-
import com.genexus.securityapicommons.encoders.HexaEncoder;
1413

1514
/**
1615
* @author sgrampone
@@ -54,7 +53,7 @@ public String doGenerateSCrypt(String password, String salt, int CPUCost, int bl
5453
this.error = eu.getError();
5554
return "";
5655
}
57-
byte[] encryptedBytes = SCrypt.generate(eu.getBytes(password), eu.getBytes(salt), CPUCost, blockSize,
56+
byte[] encryptedBytes = SCrypt.generate(eu.getBytes(password), Hex.decode(salt), CPUCost, blockSize,
5857
parallelization, keyLenght);
5958
String result = Strings.fromByteArray(Base64.encode(encryptedBytes));
6059
if (result == null || result.length() == 0) {
@@ -100,8 +99,7 @@ public String doGenerateBcrypt(String password, String salt, int cost) {
10099
return "";
101100
}
102101
EncodingUtil eu = new EncodingUtil();
103-
HexaEncoder hexa = new HexaEncoder();
104-
byte[] encryptedBytes = BCrypt.generate(eu.getBytes(password), Strings.toByteArray(hexa.fromHexa(salt)), cost);
102+
byte[] encryptedBytes = BCrypt.generate(eu.getBytes(password), Hex.decode(salt), cost);
105103
String result = Strings.fromByteArray(Base64.encode(encryptedBytes));
106104
if (result == null || result.length() == 0) {
107105
this.error.setError("PD010", "Bcrypt generation error");
@@ -143,17 +141,15 @@ public String doGenerateArgon2(String argon2Version10, String argon2HashType, in
143141
}
144142

145143
EncodingUtil eu = new EncodingUtil();
146-
HexaEncoder hexa = new HexaEncoder();
147144
byte[] bytePass = eu.getBytes(password);
148-
if(eu.hasError())
149-
{
145+
if (eu.hasError()) {
150146
this.error = eu.getError();
151147
return "";
152148
}
153149

154150
Argon2Parameters.Builder builder = new Argon2Parameters.Builder(hashType).withVersion(version)
155151
.withIterations(iterations).withMemoryPowOfTwo(memory).withParallelism(parallelism)
156-
.withSalt(Strings.toByteArray(hexa.fromHexa(salt)));
152+
.withSalt(Hex.decode(salt));
157153

158154
Argon2BytesGenerator dig = new Argon2BytesGenerator();
159155
dig.init(builder.build());
@@ -184,9 +180,8 @@ public String doGenerateArgon2(String argon2Version10, String argon2HashType, in
184180
*/
185181
private boolean areBCryptValidParameters(String pwd, String salt, int cost) {
186182
EncodingUtil eu = new EncodingUtil();
187-
HexaEncoder hexa = new HexaEncoder();
188183
byte[] pwdBytes = eu.getBytes(pwd);
189-
byte[] saltBytes = Strings.toByteArray(hexa.fromHexa(salt));
184+
byte[] saltBytes = Hex.decode(salt);
190185
if (saltBytes.length * 8 != 128) {
191186
this.error.setError("PD008", "The salt lenght must be 128 bits");
192187
return false;

0 commit comments

Comments
 (0)