问题
I have a valid P12 file. I need to instantiate an X509certificate object, so that I can use it as a client side certificate.
I realize that there is already a similar question answered here, How to instantiate javax.security.X509Certficate object from a p12 certificate (contains certificate + private key)
But in Blackberry, the getInstance(String) method is not available for KeyStore. It's available for DeviceKeyStore and TrustedKeyStore. But we can't pass the "PKCS12" parameter to the getInstance() method.
Also DeviceKeyStore or TrustedKeyStore don't have the load
methods. They have the set
methods. But I'm not sure how we can pass fileinputstream parameter to that one.
Has anyone tried this? Do you know what alternate methods are available for this?
Thanks for your help.
Edit: There is a method for doing this for PEM file,(Install SSL Certificate with BlackBerry App) which is what I used initially to try to make it work. But the formats differ. PEM is a Base64 format, and it contains just the certificate.
回答1:
You can invoke an external application for doing that. There is a partial solution: http://supportforums.blackberry.com/t5/Java-Development/Handling-a-p12-certificate-store/td-p/654127
But for some reason you don't get the import menu! The piece of code:
Invocation certInvocation = new Invocation( "path to .p12 on SD Card");
certInvocation.setResponseRequired( false );
certInvocation.setID( BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER );
certInvocation.setAction( ContentHandler.ACTION_OPEN );
certInvocation.setType( "application/x-pkcs12" );
Registry registry = Registry.getRegistry( Application.class.getName() );
try {
registry.invoke( certInvocation );
}
catch (Throwable t) {}
来源:https://stackoverflow.com/questions/13151134/how-to-instantiate-x509certificate-from-a-p12-file-in-blackberry