public static X509Certificate replaceCertPublicKey(final X509Certificate certificate,PublicKey _publicKey) throws CertificateException {
//公钥算法
String pubAlg = _publicKey.getAlgorithm();
//签名算法
String sAlg = null;
try {
sAlg = AlgorithmId.get(pubAlg).getOID().toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
//证书主题
String subjectDN = certificate.getSubjectDN().getName();
String issueDn = certificate.getIssuerDN().getName();
X500Name subject = new X500Name(subjectDN);
X500Name issuer = new X500Name(issueDn);
//组装SubjectPublicKeyInfo
byte[] publicKey = _publicKey.getEncoded();
SubjectPublicKeyInfo publicKeyInfo;
if (sAlg.equals("1.2.156.197.1.301")) {
publicKeyInfo = new SubjectPublicKeyInfo(new AlgorithmIdentifier(
sAlg), publicKey);
} else {
publicKeyInfo = new SubjectPublicKeyInfo(
ASN1Sequence.getInstance(publicKey));
}
//序列号
BigInteger serial = certificate.getSerialNumber();
//有效日期
Date notBefore = certificate.getNotBefore();
Date notAfter = certificate.getNotAfter();
//组装
X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(
issuer, serial, notBefore, notAfter, subject, publicKeyInfo);
//签名
ContentSigner signer = new ContentSigner() {
public byte[] getSignature() {
return certificate.getSignature();
}
public OutputStream getOutputStream() {
return new ByteArrayOutputStream();
}
public AlgorithmIdentifier getAlgorithmIdentifier() {
return new AlgorithmIdentifier(
AlgorithmId.sha1WithRSAEncryption_oid.toString());
}
};
//生成证书
X509CertificateHolder certHolder = certBuilder.build(signer);
byte[] certBuf = null;
try {
certBuf = certHolder.getEncoded();
} catch (IOException e) {
e.printStackTrace();
}
CertificateFactory cf = CertificateFactory.getInstance("X509");
return (X509Certificate) cf
.generateCertificate(new ByteArrayInputStream(certBuf));
}
分享到:
相关推荐
纯属上级考验,自己下的asn代码查看器,网上找的标准, 和x509证书编码规则
1、完整的X509证书解析方案,C语言实现; 2、内含测试程序,在Linux环境下进入目录后make即可编译,已经在ubuntu16.04环境下编译测试OK; 4、已经在扫码POS认证中得到应用,解析出证书的序列号、公钥; 5、漂亮的...
1.C语言实现完整的X509证书解析方案; 2.解析出证书的序列号、公钥;
用于 X.509 公钥证书、属性证书、认证请求和认证路径验证的 PHP 库。 介绍 该库提供了 X.509 证书的纯 PHP 实现。 类层次结构适应 ASN.1 类型,这使得使用相应的 RFC 作为参考文档变得容易。 特征 X.509 证书 ( ) ...
X.509对公钥证书的格式,撤销证书列表(CRLs),证书验证路径算法等进行了规定。 一个X.509证书中包含了其版本号,证书序列号,签名算法,签发者,证书主体,有效期,公钥,公钥密钥等信息。证书中的信息使用 ASN.1...
X.509对公钥证书的格式,撤销证书列表(CRLs),证书验证路径算法等进行了规定。 一个X.509证书中包含了其版本号,证书序列号,签名算法,签发者,证书主体,有效期,公钥,公钥密钥等信息。证书中的信息使用 ASN.1...
Internet X.509 公钥基础设施--证书和CRL简介
x509.js 在 javascript 中解析 x509 证书和密钥(通过 emscripten)安装 npm install x509.js浏览器使用TODO(接受拉取请求)用法 var fs = require ( 'fs' ) ;var x509 = require ( 'x509.js' ) ;var parsedData = ...
Internet X.509 公钥基础设施(RFC2459中文翻译)
1. PHP下将X509的证书key转为PEM编码,便于OPENSSL处理; 2. 将Modulus/Exponent形式的RSA Key转为PEM编码格式。
这是一个互联网标准轨道文件。 本文档是互联网工程任务组(IETF)的产品。 它代表了IETF社区的共识。 已获得公众意见审查,并获准由互联网工程指导小组(IESG)出版。
定义了一类新的属性——NewPKI属性,并且将NewPKI属性与X.509公钥证书相结合,从而提出一类新的证书——融合证书。融合证书保留与X.509 v3证书相同的证书格式,且能够将属性加到X.509身份证书中,它能够作为一个理想...
有朋友叫帮忙做有一个RSA加解密的帮助类,后面发现是与JAVA做交互,对方提供了公钥cer文件。由于C#RSA只支持公钥加密,私钥解密。而现在只能使用公钥加密,公钥解密,而且C#与Java并不互通,所以采用第三方类库 ...
将 OpenSSH 公钥转换为 x.509 公钥。 用法 const fs = require('fs'); const ospkToX509 = require('opensshpubkey-to-x509-converter'); const openSSHPubKey = fs.readFileSync('path/to/id_rsa.pub') const x509...
证书创建工具生成仅用于测试目的的 X.509 证书。它创建用于数字签名的公钥和私钥对,并将其存储在证书文件中。此工具还将密钥对与指定发行者的名称相关联,并创建一个 X.509 证书,该证书将用户指定的名称绑定到...
基于无证书公钥的无线传感器密钥管理方案,申 远,杨延平,本文对现有的一个无线传感器密钥管理方案进行安全性分析,通过分析表明,该方案对于簇头节点的伪造攻击是不安全的。进而在无证书公�
X.509证书的ASN1 DER解码器 要求 iOS 9.0以上| macOS 10.10以上 Xcode 9 一体化 CocoaPods(iOS 9+,OS X 10.10+) 您可以使用将ASN1Decoder添加到您的Podfile来安装它: platform :ios , '9.0' use_frameworks! ...
数字证书的生成 数字证书包含证书中所标识的实体的公钥(就是说你的证书里有你的公钥),由于证书将公钥与特定的个人匹配,并且该证书的真实性由颁发机构保证(就是说可以让大家相信你的证书是真的),因此,数字...
介绍公钥证书的一些知识