我在gradle测试代码中收到错误。在这行代码上生成了一个例外:account.setAccountNumber(encryptor.encrypt(" 999999999"))。
这篇文章可能有关:
What is the correct way to configure a spring TextEncryptor for use on Heroku
com.distributedfinance.mbi.bai.lookup.AccountLookupSpec > constructor missing encryptor FAILED
19:05:00.431 [DEBUG] [TestEventLogger] java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
19:05:00.431 [DEBUG] [TestEventLogger] at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:110)
19:05:00.431 [DEBUG] [TestEventLogger] at org.springframework.security.crypto.encrypt.AesBytesEncryptor.encrypt(AesBytesEncryptor.java:65)
19:05:00.431 [DEBUG] [TestEventLogger] at org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor.encrypt(HexEncodingTextEncryptor.java:36)
19:05:00.431 [DEBUG] [TestEventLogger] at com.distributedfinance.mbi.bai.lookup.AccountLookupSpec.setup(AccountLookupSpec.groovy:26)
19:05:00.431 [DEBUG] [TestEventLogger]
19:05:00.431 [DEBUG] [TestEventLogger] Caused by:
19:05:00.431 [DEBUG] [TestEventLogger] java.security.InvalidKeyException: Illegal key size
19:05:00.431 [DEBUG] [TestEventLogger] at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1034)
19:05:00.431 [DEBUG] [TestEventLogger] at javax.crypto.Cipher.implInit(Cipher.java:800)
19:05:00.431 [DEBUG] [TestEventLogger] at javax.crypto.Cipher.chooseProvider(Cipher.java:859)
19:05:00.432 [DEBUG] [TestEventLogger] at javax.crypto.Cipher.init(Cipher.java:1370)
19:05:00.432 [DEBUG] [TestEventLogger] at javax.crypto.Cipher.init(Cipher.java:1301)
19:05:00.432 [DEBUG] [TestEventLogger] at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:105)
19:05:00.432 [DEBUG] [TestEventLogger] ... 3 more
我在IntelliJ Idea中运行Java 1.8
$ gradle -version
------------------------------------------------------------
Gradle 2.3-20141027185330+0000
------------------------------------------------------------
Build time: 2014-10-27 18:53:30 UTC
Build number: none
Revision: f8200ecfed690fe7e2183d60a2afa85069678fa3
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_05 (Oracle Corporation 25.5-b02)
OS: Mac OS X 10.11 x86_64
$ gradle clean build
...
:测试
com.distributedfinance.mbi.bai.lookup.AccountLookupSpec > constructor missing encryptor FAILED
java.lang.IllegalArgumentException at AccountLookupSpec.groovy:26
Caused by: java.security.InvalidKeyException at AccountLookupSpec.groovy:26
例外是在Groovy代码中:
AccountLookup accountLookup
List<Account> accounts
AccountRepository accountRepository
TextEncryptor encryptor
def setup() {
accountRepository = Mock()
encryptor = Encryptors.text("password", "blahblahbla")
***account.setAccountNumber(encryptor.encrypt("999999999"))***
...
def "constructor missing encryptor"() {
when:
new AccountLookup(null, accountRepository)
then:
IllegalArgumentException e = thrown()
e.getMessage() == "Encryptor is null"
}
我尝试通过在Groovy代码中设置断点(在&#39; attach&#39;以及&#39; listen&#39;模式下)从IntelliJ Idea中调试它:
$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
$ gradle build
Listening for transport dt_socket at address: 5005
但我从来没有达到过断点。
有什么想法吗?
答案 0 :(得分:0)
看起来你的盐很糟糕,除非那只是一个不好的例子?
第二个arg是一个“盐”,定义为: salt - 用于生成密钥的十六进制编码,随机,站点全局salt值
你的是“blahblahbla”......这不是十六进制编码。