从X509Certificate获取PrivateKey

时间:2017-06-27 10:18:32

标签: java x509certificate bouncycastle x509

以下是使用Let's Encrypt生成SSL证书的代码(基于https://github.com/zero11it/acme-client):

AcmeChallengeListener challengeListener = new HttpChallengeListener(sessionToken, appObjectId, userId, domains[0], "");
Acme acme = new Acme(CA_STAGING_URL, new DefaultCertificateStorage(true), true, true);
X509Certificate cert = acme.getCertificate(domains, AGREEMENT_URL, contacts, challengeListener);
String fullchain = CertificateHelper.x509ToBase64PEMString(cert);

有没有办法获取PrivateKey并将其作为字符串与-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----一起使用?因此,我们的应用程序可以将其上传到我们的NGINX服务器。

1 个答案:

答案 0 :(得分:1)

解决方案是修改库并公开证书存储,如下所示:

AlertDialog.Builder alt_bld = new AlertDialog.Builder(this, R.style.AlertDialogStyle); alt_bld.setTitle("Select Date"); try{ final View view = View.inflate(addAlarm.this, R.layout.alert_dialog_radiogroup, null); radioGroup = (RadioGroup)view.findViewById(R.id.radio); radioGroup.clearCheck(); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) { //My code to handle checked radio button. } }); alt_bld.setView(view); } catch (Exception e){ e.printStackTrace(); } //setting +ve and -ve buttons here. ... AlertDialog alert = alt_bld.create(); alert.show();

此处应用可以获取 public CertificateStorage getCertificateStorage() { return certificateStorage; }