Signing a Document: Step 2. Create the Key
char[] password = "secret".toCharArray();
KeyStore store = KeyStore.getInstance("JKS");
InputStream keys = new FileInputStream("keys.jks");
store.load(keys, password);
KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry
("theKey", new KeyStore.PasswordProtection(password));
X509Certificate cert = (X509Certificate) entry.getCertificate();
KeyInfoFactory keyFactory = factory.getKeyInfoFactory();
List certs = new ArrayList();
certs.add(cert.getSubjectX500Principal().getName());
certs.add(cert);
X509Data data = keyFactory.newX509Data(certs);
List dataList = Collections.singletonList(data);
KeyInfo key = keyFactory.newKeyInfo(dataList);