Issue
In spring.application I've specified keystore name and password. I'd like to sign some data with Signature.sign() from java security, but to do that I'd need Keystore. Is there a way to get Spring managed keystore bean, or do I have to create my own keystore, even when it's already used by spring?
Solution
You can just use the
@Autowired
private KeyStore keyStore;
if you've configured it correctly in your XML/Java configuration like so
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:crypt="http://springcryptoutils.com/schema/crypt"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://springcryptoutils.com/schema/crypt http://springcryptoutils.com/schema/crypt.xsd">
<crypt:keystore id="keystore"
location="somePath}"
password="somePassword"/>
</beans>
Answered By - N4zroth
Answer Checked By - Mary Flores (JavaFixing Volunteer)