You can provide keystores to already existing implementations for data sending over http, which will fetch the keystore and perform all the necessary stuff so you don't have to.
For server-side authentication this would be a keystore = KeyStore.getInstance("JKS"), containing all the trusted certificates.
For client-side authentication, if applicable (you need to verify yourself) also such implementation already exist
where you just provide your client 'keystore' => this one will contain your certificate and it's private key => KeyStore.getInstance("PKCS12")
Then finally you want to store these stuff to database, here it gets a bit tricky.. Keystores are secured, so you can not just write it away.. you have to use the keystore.store(OutPutstream, password)..
What I find best is for instance:
@Entity
public class MyKeyStoreClass {
private Long id;
@Transient
private KeyStore keystore;
private String passwordForKeyStore;
private Byte[] keyStoreAsBytes;
@PreUpdate
@PrePersist
public void concertKeyStoreToBytes() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
keystore.store(byteArrayOutputStream,
passwordForKeyStore.toCharArray());
keyStoreAsBytes = byteArrayOutputStream.toByteArray();
}
@PostLoad
public void getKeyStore() {
if (keystore == null && keyStoreAsBytes != null) {
keyStore = KeyStore.getInstance(getKeystoreType().getType());
keyStore.load(new ByteArrayInputStream(keystoreAsBytes), passwordForKeyStore.toCharArray());
}
}
The above code is not 100% correct, but it gives you a good idea of what I mean, If you don't work with annotations, you can do it using another approach but I think my point is clear ;)