I'm working in a program that encripts and decripts stuff using hybrid method, this is, using AES simmetrical and RSA asimmetrical keys. All of this keys get stored in a KeyStore .jks file.
Problem: KeyStore java class needs a Certificate array when you are trying to entry a private key into the keystore file. For example, this code:
String alias = "sth";
Key myKey = generator.generateKeyPair().getPrivate();
char[] keyStorePass = {'1', '2', '3', '4'};
myKeyStore.setKeyEntry(alias, myKey, keyStorePass, null);
will throw an exception because myKey is a private key and I'm providing no certificates to setKeyEntry.
java.lang.IllegalArgumentException: Private key must be accompanied by certificate chain
Now, the real problem here is that I don't know how to generate a certificate to provide to KeyStore class. Java documentation tells you that you need to provide a Certificate[] object, but Eclipse IDE tells me Certificate class is deprecated (which, IIRC, means it shouldn't be used anymore) and also can't be instantiated. So how do I generate a certificate to use across my program?