Cant' retrieve privatekey cert in CMS decryption

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Cant' retrieve privatekey cert in CMS decryption

cryptoSad

Hi all!

I’m getting mad trying to decrypt a pkcs\CMS file with Luna HSM.

The method I use works well with a JKS but on the Hsm I get a null pointer because it can retrieve the Certificate associated with the key.

The exception is  in the new  JceKeyTransRecipientId because the X509Certificate is null

 

RecipientInformation recipient = recipients.get(new JceKeyTransRecipientId((java.security.cert.X509Certificate)jcaProvider.getKeystore().getCertificate(alias)));

 

The code is quite “standard”:

 

       RecipientInformation recipient = recipients.get(new JceKeyTransRecipientId((java.security.cert.X509Certificate)jcaProvider.getKeystore().getCertificate(alias)));

                   

       log.info("selected recipient by TransRecipientid.Rec alg:{}",recipient.getKeyEncryptionAlgOID());

                   

       if (recipient != null) {

                    

             log.info("recipient!=null getting JceKeyTransEnvelopedRecipient");

                    

               JceKeyTransEnvelopedRecipient trans=new JceKeyTransEnvelopedRecipient((PrivateKey)jcaProvider.getKeystore().getKey(alias,jcaProvider.getPwd().toCharArray()));

                                                                   

                                                                                                                                                         

             CMSTypedStream cmsTs= recipient.getContentStream(trans);

 

and so on…..

 

Any ideas?

 

Thanks a lot