2015-10-07 25 views
0

我得到的錯誤在gradle測試代碼。此行代碼生成異常:account.setAccountNumber(encryptor.encrypt(「999999999」))。錯誤:導致:java.security.InvalidKeyException在AccountLookupSpec.groovy

這個帖子可能涉及:

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

$ 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 

運行Java 1.8 ...

:測試

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代碼(設置斷點在 '連接' 從IntelliJ IDEA的調試這一點,也「聽」模式):

enter image description here

enter image description here

enter image description here

$ 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

如果您列出了Spring標籤,您可能會省下一些努力。以前從未見過TextEncryptor。 – billjamesdev

回答

0

看起來你的鹽不好,除非這只是一個壞例子?

從文檔:https://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/apidocs/org/springframework/security/crypto/encrypt/Encryptors.html

的第二arg是「鹽」,其被定義爲: 鹽 - 一個十六進制編碼的,隨機的,現場全局鹽值用來生成密鑰

你的是「blahblahbla」...這是不是十六進制編碼。

+0

我改變了第二個參數(例如 - salt)爲「blahblahbla」,因爲我不想把真正的十六進制值放在Stack Overflow中。 – dbl001

+0

在真正的groovy代碼中,有一個真正的十六進制值。這是否意味着它不好?它應該如何生成? – dbl001

+0

第二個參數(例如 - 'salt')是否與特定的SSH證書相對應? – dbl001