The publickey is not stored separately in a P12, so you do need to extract
it
from the cert, but thats not hard.
PublicKey k = loaded_keystore.getCertificate(alias).getPublicKey();
/* or cast to ECPublicKey if you need to be specific */
From: [email protected]
[mailto:[email protected]] On Behalf Of Marcio Campos de Lima
Sent: Monday, March 10, 2014 10:24
To: [email protected]
Subject: *** Spam *** Re: Flushing encrypted data to file
Hi
Thanks for the code.
Is it the only way to get the public key ?
Is it possible to generate the key pair and store both of them into two
PEM files and then to store in the PKCS12?
my current java code to use the openssl generated P12 file is:
// Load Key Pair: load the PKCS12 keystore in the class
public void load_keypair (String keyname, String password)
{
try {
Security.addProvider(new
org.bouncycastle.jce.provider.BouncyCastleProvider());
p12 = KeyStore.getInstance("PKCS12","BC");
p12.load(new FileInputStream(keyname), password.toCharArray());
eccPrivatekey=(ECPrivateKey)p12.getKey("PrivateKey",
password.toCharArray());
// here is the problem. I cannot get the public key like I am
doing with the private key whitout parsing the certificate???????
eccPublickey=(ECPublicKey)p12.getKey("PrivateKey",
password.toCharArray()); //
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
Em 10/03/2014, à(s) 09:50, Fredrik Jansson <[email protected]>
escreveu:
Hi!
Some example code to extract a cert from a P12 file:
BIO* certFile = BIO_new_file("cert path", "r");
PKCS12* p12 = nullptr;
X509* cert = nullptr;
if (!certFile) {
goto done;
}
p12 = d2i_PKCS12_bio(certFile, nullptr);
if (!p12) {
goto done;
}
if (!PKCS12_parse(p12, "P12 password", &g_pk, &cert, nullptr)) {
goto done;
}
done:
X509_free(cert);
PKCS12_free(p12);
BIO_free(certFile);
On Mon, Mar 10, 2014 at 1:09 PM, Marcio Campos de Lima
<[email protected]> wrote:
Hi
How can I get the Public Key from a PKCS12 keystone?
Do I need to parse the certificate ? Is there a way to store the public key
into the PKCS12 keystone?
Thanks
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]