Я пытаюсь написать тестовый пример JUnit для приведенного ниже кода. Я использую Encryptors библиотеки Spring-Security-Crypto. Когда я пытаюсь запустить код, я могу успешно зашифровать строку, но когда я запускаю тестовый пример, я получаю сообщение об ошибке.
код
public String standardEncryption(String value) {
if (!isNullOrEmpty(value)) {
return Encryptors.text(password, salt).encrypt(value);
}
return value;
}
Тестовый набор Junit
@Test
public void can_standardEncryption() {
String value = someNumericString(10);
String result = encryption.standardEncryption(value);
assertThat(result).isNotNull();
assertThat(result.equals(value)).isFalse();
assertThat(textEncryptor.decrypt(result)).isEqualTo(value);
assertThat(result.equals(textEncryptor.encrypt(value))).isFalse();
}
Ошибка
java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:120)
at org.springframework.security.crypto.encrypt.AesBytesEncryptor.encrypt(AesBytesEncryptor.java:115)
at org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor.encrypt(HexEncodingTextEncryptor.java:36)
at something(something.java:25)
at something(something.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
Caused by: java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
at javax.crypto.Cipher.implInit(Cipher.java:805)
at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
at javax.crypto.Cipher.init(Cipher.java:1396)
at javax.crypto.Cipher.init(Cipher.java:1327)
at org.springframework.security.crypto.encrypt.CipherUtils.initCipher