/** * Save private key and public key and certificate in keystore. * * @param certId The certificate ID or alias in the keystore. * @param certPem The certificate in PEM format. * @param keyPem The private key in PEM format. Can handle with or without * BEGIN RSA/END RSA strings. * @param keystorePath The path to keystore. * @param keystoreName The name of the keystore. * @param keystorePassword The password for the keystore. */ public static void saveCertificateAndPrivateKey(String certId, String certPem, String keyPem, String keystorePath, String keystoreName, String keystorePassword) { PrivateKeyReader privateKeyReader = new PrivateKeyReader(keyPem); PrivateKey privateKey; try { privateKey = privateKeyReader.getPrivateKey(); } catch (IOException e) { throw new AmazonClientException("An error occurred saving the certificate and key.", e); } catch (InvalidKeySpecException e) { throw new AWSIotCertificateException( "An error occurred saving the certificate and key.", e); } saveCertificateAndPrivateKey(certId, certPem, privateKey, keystorePath, keystoreName, keystorePassword); }
PrivateKey pk = (new PrivateKeyReader("myPrivateKeyFile.pem")).getPrivateKey();
/** * Save private key and public key and certificate in keystore. * * @param certId The certificate ID or alias in the keystore. * @param certPem The certificate in PEM format. * @param keyPem The private key in PEM format. Can handle with or without * BEGIN RSA/END RSA strings. * @param keystorePath The path to keystore. * @param keystoreName The name of the keystore. * @param keystorePassword The password for the keystore. */ public static void saveCertificateAndPrivateKey(String certId, String certPem, String keyPem, String keystorePath, String keystoreName, String keystorePassword) { PrivateKeyReader privateKeyReader = new PrivateKeyReader(keyPem); PrivateKey privateKey; try { privateKey = privateKeyReader.getPrivateKey(); } catch (IOException e) { throw new AmazonClientException("An error occurred saving the certificate and key.", e); } catch (InvalidKeySpecException e) { throw new AWSIotCertificateException( "An error occurred saving the certificate and key.", e); } saveCertificateAndPrivateKey(certId, certPem, privateKey, keystorePath, keystoreName, keystorePassword); }