JKS文件复制与下载

本文详细描述了如何在远程服务器上创建X509V3JKS证书,包括设置有效期、序列号等,然后将证书和密钥复制到本地,并使用KeyStore加载,确保ALIAS和PASSWORD的一致性。
摘要由CSDN通过智能技术生成

远程服务器创建的JKS证书下载到本地 并对业务数据进行签名实现

一、创建远程证书



private X509V3CertificateGenerator builder(int days){
    var cert=new X509V3CertificateGenerator();
    cert.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    cert.setIssuerDN(new X500Principal(ISSUER));
    cert.setNotBefore(new Date(System.currentTimeMillis()-1000L*60*60*24));
    cert.setNotAfter(new Date(System.currentTimeMillis()+1000L*60*60*24*days));
    var subject= Optional.ofNullable(System.getenv("appid")).orElse(SUBJECT);
    cert.setSubjectDN(new X500Principal(subject));
    cert.setPublicKey(publicKey);
    cert.setSignatureAlgorithm(SIGNATURE_ALGORITHM);
    return cert;
}

二、复制JKS文件到本地

三、本地加载JKS文件

    var keyStore=KeyStore.getInstance("JKS")
    var filename= Optional.ofNullable(System.getenv("appid")).orElse(ALIAS);
    keyStore.load(new FileInputStream(filename+".jks"),PASSWORD);
    var cert=(X509Certificate)keyStore.getCertificate(ALIAS);
    return Map.of("pri",keyStore.getKey(ALIAS,PASSWORD),"pub",cert.getPublicKey());

这样导入私钥和公钥就成功了

注意ALIAS与PASSWORD与远程生成证书时应相同。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恒云客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值