|
10 | 10 |
|
11 | 11 | import com.genexus.cryptography.commons.PasswordDerivationObject; |
12 | 12 | import com.genexus.securityapicommons.config.EncodingUtil; |
13 | | -import com.genexus.securityapicommons.encoders.HexaEncoder; |
14 | 13 |
|
15 | 14 | /** |
16 | 15 | * @author sgrampone |
@@ -54,7 +53,7 @@ public String doGenerateSCrypt(String password, String salt, int CPUCost, int bl |
54 | 53 | this.error = eu.getError(); |
55 | 54 | return ""; |
56 | 55 | } |
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, |
58 | 57 | parallelization, keyLenght); |
59 | 58 | String result = Strings.fromByteArray(Base64.encode(encryptedBytes)); |
60 | 59 | if (result == null || result.length() == 0) { |
@@ -100,8 +99,7 @@ public String doGenerateBcrypt(String password, String salt, int cost) { |
100 | 99 | return ""; |
101 | 100 | } |
102 | 101 | 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); |
105 | 103 | String result = Strings.fromByteArray(Base64.encode(encryptedBytes)); |
106 | 104 | if (result == null || result.length() == 0) { |
107 | 105 | this.error.setError("PD010", "Bcrypt generation error"); |
@@ -143,17 +141,15 @@ public String doGenerateArgon2(String argon2Version10, String argon2HashType, in |
143 | 141 | } |
144 | 142 |
|
145 | 143 | EncodingUtil eu = new EncodingUtil(); |
146 | | - HexaEncoder hexa = new HexaEncoder(); |
147 | 144 | byte[] bytePass = eu.getBytes(password); |
148 | | - if(eu.hasError()) |
149 | | - { |
| 145 | + if (eu.hasError()) { |
150 | 146 | this.error = eu.getError(); |
151 | 147 | return ""; |
152 | 148 | } |
153 | 149 |
|
154 | 150 | Argon2Parameters.Builder builder = new Argon2Parameters.Builder(hashType).withVersion(version) |
155 | 151 | .withIterations(iterations).withMemoryPowOfTwo(memory).withParallelism(parallelism) |
156 | | - .withSalt(Strings.toByteArray(hexa.fromHexa(salt))); |
| 152 | + .withSalt(Hex.decode(salt)); |
157 | 153 |
|
158 | 154 | Argon2BytesGenerator dig = new Argon2BytesGenerator(); |
159 | 155 | dig.init(builder.build()); |
@@ -184,9 +180,8 @@ public String doGenerateArgon2(String argon2Version10, String argon2HashType, in |
184 | 180 | */ |
185 | 181 | private boolean areBCryptValidParameters(String pwd, String salt, int cost) { |
186 | 182 | EncodingUtil eu = new EncodingUtil(); |
187 | | - HexaEncoder hexa = new HexaEncoder(); |
188 | 183 | byte[] pwdBytes = eu.getBytes(pwd); |
189 | | - byte[] saltBytes = Strings.toByteArray(hexa.fromHexa(salt)); |
| 184 | + byte[] saltBytes = Hex.decode(salt); |
190 | 185 | if (saltBytes.length * 8 != 128) { |
191 | 186 | this.error.setError("PD008", "The salt lenght must be 128 bits"); |
192 | 187 | return false; |
|
0 commit comments