我需要知道是否可以从KeyStore检索密钥而不提供'storepass'.此处的文档说"当从密钥库中检索信息时,密码是可选的;如果没有给出密码,则无法检查检索到的信息的完整性并显示警告"
但是,当我尝试在没有密码的情况下获取密钥时,我得到"java.lang.IllegalArgumentException:password not not null"异常.
以下是我创建KeyStore的方法
keytool -genseckey -alias"myKey"-keystore KEYSTORE.jks -storepass"password"-storetype"JCEKS"-keyalg AES -keysize 128
我尝试按如下方式检索它
final KeyStore keyStore = KeyStore.getInstance("JCEKS");
keyStore.load(new FileInputStream(new File("C:\\temp\\keytool\\KEYSTORE.jks")),
null);
final Key key = keyStore.getKey("myKey", null);
Run Code Online (Sandbox Code Playgroud)
这引发了以下异常
java.lang.IllegalArgumentException: password can't be null
at com.sun.crypto.provider.SunJCE_z.<init>(DashoA13*..)
at com.sun.crypto.provider.JceKeyStore.engineGetKey(DashoA13*..)
at java.security.KeyStore.getKey(KeyStore.java:763)
Run Code Online (Sandbox Code Playgroud)
我完全误解了文档吗?有没有其他办法解决这个问题,因为我没有看到在我的代码中将'storepass'清楚地存储在每个人都可以看到它的位置,因此使密码无用.
我正在使用Spring 3.1并使用以下spring配置,我LocalValidatorFactoryBean使用自己的显式创建ValidationMessageSource.我的类路径中有Hibernate Validator 4.1.
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>ValidatorMsgID</value>
</list>
</property>
</bean>
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource"/>
</bean>
<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/>
Run Code Online (Sandbox Code Playgroud)
但是我注意到,LocalValidatorFactoryBean通过在类afterPropertiesSet方法中调试调试来创建两次.第一次是我在spring配置中定义的explicite bean,但是随后同一个类被类隐式重新实例化DefaultListableBeanFactory- 显然这次没有validationMessageSource.因此,当Spring确实使用LocalValidatorFactoryBean默认Hibernates messagesource而不是我指定的那个时使用它.
好吧,进一步研究它似乎这是由mvc:annotation-driven我在spring配置中引起的.任何指针仍然会有所帮助