SEC-1689: Moved core codec code into crypto package and removed existing duplication (Hex encoding etc). Refactoring of crypto code to use CharSequence for where possible instead of String.
This commit is contained in:
@@ -10,9 +10,9 @@ import org.junit.Test;
|
||||
public class EncryptorsTests {
|
||||
|
||||
@Test
|
||||
public void standard() {
|
||||
public void standard() throws Exception {
|
||||
BytesEncryptor encryptor = Encryptors.standard("password", "5c0744940b5c369b");
|
||||
byte[] result = encryptor.encrypt("text".getBytes());
|
||||
byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
|
||||
assertNotNull(result);
|
||||
assertFalse(new String(result).equals("text"));
|
||||
assertEquals("text", new String(encryptor.decrypt(result)));
|
||||
|
||||
@@ -6,7 +6,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.crypto.util.EncodingUtils;
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
|
||||
public class KeyGeneratorsTests {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class KeyGeneratorsTests {
|
||||
StringKeyGenerator keyGenerator = KeyGenerators.string();
|
||||
String hexStringKey = keyGenerator.generateKey();
|
||||
assertEquals(16, hexStringKey.length());
|
||||
assertEquals(8, EncodingUtils.hexDecode(hexStringKey).length);
|
||||
assertEquals(8, Hex.decode(hexStringKey).length);
|
||||
String hexStringKey2 = keyGenerator.generateKey();
|
||||
assertFalse(hexStringKey.equals(hexStringKey2));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.security.crypto.util;
|
||||
package org.springframework.security.crypto.password;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -7,6 +7,7 @@ import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.crypto.password.Digester;
|
||||
|
||||
public class DigesterTests {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class StandardPasswordEncoderTests {
|
||||
@Test
|
||||
public void matchesLengthChecked() {
|
||||
String result = encoder.encode("password");
|
||||
assertFalse(encoder.matches("password", result.substring(0,result.length()-1)));
|
||||
assertFalse(encoder.matches("password", result.substring(0,result.length()-2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -6,20 +6,21 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
|
||||
public class EncodingUtilsTests {
|
||||
|
||||
@Test
|
||||
public void hexEncode() {
|
||||
byte[] bytes = new byte[] { (byte)0x01, (byte)0xFF, (byte)65, (byte)66, (byte)67, (byte)0xC0, (byte)0xC1, (byte)0xC2 };
|
||||
String result = EncodingUtils.hexEncode(bytes);
|
||||
String result = new String(Hex.encode(bytes));
|
||||
assertEquals("01ff414243c0c1c2", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hexDecode() {
|
||||
byte[] bytes = new byte[] { (byte)0x01, (byte)0xFF, (byte)65, (byte)66, (byte)67, (byte)0xC0, (byte)0xC1, (byte)0xC2 };
|
||||
byte[] result = EncodingUtils.hexDecode("01ff414243c0c1c2");
|
||||
byte[] result = Hex.decode("01ff414243c0c1c2");
|
||||
assertTrue(Arrays.equals(bytes, result));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user