Skip to content

Commit e546d0f

Browse files
committed
Fixed api usage for major update
1 parent b3629b4 commit e546d0f

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

crypto-shiro/src/main/java/de/dominikschadow/javasecurity/hash/SHA512.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.shiro.crypto.hash.DefaultHashService;
2121
import org.apache.shiro.crypto.hash.Hash;
2222
import org.apache.shiro.crypto.hash.HashRequest;
23-
import org.apache.shiro.util.ByteSource;
23+
import org.apache.shiro.lang.util.ByteSource;
2424

2525
import java.util.Arrays;
2626

@@ -35,30 +35,26 @@ public class SHA512 {
3535
* Nothing up my sleeve number as private salt, not good for production.
3636
*/
3737
private static final byte[] PRIVATE_SALT_BYTES = {3, 1, 4, 1, 5, 9, 2, 6, 5};
38-
private static final int ITERATIONS = 1000000;
3938

4039
public Hash calculateHash(String password) {
4140
ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
4241
DefaultHashService hashService = new DefaultHashService();
43-
hashService.setPrivateSalt(privateSalt);
44-
hashService.setGeneratePublicSalt(true);
45-
hashService.setHashIterations(ITERATIONS);
4642

4743
HashRequest.Builder builder = new HashRequest.Builder();
4844
builder.setSource(ByteSource.Util.bytes(password));
45+
builder.setSalt(privateSalt);
46+
builder.setAlgorithmName("SHA-512");
4947

5048
return hashService.computeHash(builder.build());
5149
}
5250

5351
public boolean verifyPassword(byte[] originalHash, ByteSource publicSalt, String password) {
54-
ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
5552
DefaultHashService hashService = new DefaultHashService();
56-
hashService.setPrivateSalt(privateSalt);
57-
hashService.setHashIterations(ITERATIONS);
5853

5954
HashRequest.Builder builder = new HashRequest.Builder();
6055
builder.setSource(ByteSource.Util.bytes(password));
6156
builder.setSalt(publicSalt);
57+
builder.setAlgorithmName("SHA-512");
6258

6359
Hash comparisonHash = hashService.computeHash(builder.build());
6460

crypto-shiro/src/main/java/de/dominikschadow/javasecurity/symmetric/AES.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
*/
1818
package de.dominikschadow.javasecurity.symmetric;
1919

20-
import org.apache.shiro.crypto.AesCipherService;
21-
import org.apache.shiro.util.ByteSource;
20+
21+
import org.apache.shiro.crypto.cipher.AesCipherService;
22+
import org.apache.shiro.lang.util.ByteSource;
2223

2324
import java.security.Key;
2425

@@ -44,8 +45,6 @@ public byte[] encrypt(Key key, byte[] initialText) {
4445

4546
public byte[] decrypt(Key key, byte[] ciphertext) {
4647
AesCipherService cipherService = new AesCipherService();
47-
ByteSource plainText = cipherService.decrypt(ciphertext, key.getEncoded());
48-
49-
return plainText.getBytes();
48+
return cipherService.decrypt(ciphertext, key.getEncoded()).getClonedBytes();
5049
}
5150
}

crypto-shiro/src/test/java/de/dominikschadow/javasecurity/hash/SHA512Test.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void givenIdenticalPasswordsWhenComparingHashesReturnsTrue() {
3636
Assertions.assertAll(
3737
() -> assertNotNull(hash.getSalt()),
3838
() -> assertNotNull(hash.getBytes()),
39-
() -> assertEquals(1000000, hash.getIterations()),
39+
() -> assertEquals(50000, hash.getIterations()),
4040
() -> assertEquals("SHA-512", hash.getAlgorithmName()),
4141
() -> assertTrue(hashMatches)
4242
);
@@ -52,7 +52,7 @@ void givenNotIdenticalPasswordsWhenComparingHashesReturnsFalse() {
5252
Assertions.assertAll(
5353
() -> assertNotNull(hash.getSalt()),
5454
() -> assertNotNull(hash.getBytes()),
55-
() -> assertEquals(1000000, hash.getIterations()),
55+
() -> assertEquals(50000, hash.getIterations()),
5656
() -> assertEquals("SHA-512", hash.getAlgorithmName()),
5757
() -> assertFalse(hashMatches)
5858
);

crypto-shiro/src/test/java/de/dominikschadow/javasecurity/symmetric/AESTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package de.dominikschadow.javasecurity.symmetric;
1919

2020
import de.dominikschadow.javasecurity.Keystore;
21-
import org.apache.shiro.codec.CodecSupport;
21+
import org.apache.shiro.lang.codec.CodecSupport;
2222
import org.junit.jupiter.api.Assertions;
2323
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;

0 commit comments

Comments
 (0)