gpt4 book ai didi

java - 将属性放入 X500Name Builder Bouncy CaSTLe 以生成 PKCS10

转载 作者:行者123 更新时间:2023-11-30 04:10:00 31 4
gpt4 key购买 nike

我们正在尝试生成 PKCS10CertificationRequest(又名 Der 格式的 CSR),我们知道如何完成,我将放置该生成的代码,但对于 X500Name,我们使用 X500NameBuilder,这确实很有帮助,但我们正在使用的样式是 BCStyle,包括几乎所有需要的数据。

问题是我们需要放置另一个不在 bcstyle 中的数据(数据在此处 http://www.alvestrand.no/objectid/2.5.4.45.html 和此处 http://www.alvestrand.no/objectid/2.5.4.23.html 中指定)并且确实不知道如何放置它,我们认为正在创建一个新的 X500NameStyle,但我们不知道该怎么做。

谁能向我们解释一下该怎么做

感谢支持

PS:我们正在使用的代码

public PKCS10CertificationRequest generatedCSR(PrivateKey key, PublicKey pkey, Map<String,String> certdata, String CSRAlgorithm, String name, KeyFileManager kfm) throws OperatorCreationException, IOException
{
Log.i(LOGCERT, "iniciando generacion de CSR");
this.mensaje(LogType.MENI, "Se a iniciado la generacion de un CSR");
ContentSigner signer = new JcaContentSignerBuilder(CSRAlgorithm).build(key);
X500NameBuilder namebuilder = new X500NameBuilder(X500Name.getDefaultStyle());
namebuilder.addRDN(BCStyle.CN, certdata.get("CN"));
namebuilder.addRDN(BCStyle.OU, certdata.get("OU"));
namebuilder.addRDN(BCStyle.O, certdata.get("O"));
namebuilder.addRDN(BCStyle.L, certdata.get("L"));
namebuilder.addRDN(BCStyle.ST, certdata.get("ST"));
namebuilder.addRDN(BCStyle.C, certdata.get("C"));
namebuilder.addRDN(BCStyle.EmailAddress, certdata.get("EMAIL"));
PKCS10CertificationRequestBuilder csrbuilder = new JcaPKCS10CertificationRequestBuilder(namebuilder.build(),pkey);
PKCS10CertificationRequest csr = csrbuilder.build(signer);
if(kfm.salvarLlave(csr.getEncoded(), KeyFileManager.CSRFILE, name)){
Log.i(LOGCERT, "CSR Almacenado");
return csr;
}
else{
Log.i(LOGCERT, "CSR no almacenado");
return csr;
}
}

最佳答案

我们找到了问题的解决方案,我们唯一需要做的就是创建 ASN1ObjectIdentifier("");, to put the missing data to the CSR



<p>here is the correcte code </p>

public PKCS10CertificationRequest generatedCSR(PrivateKey key, PublicKey pkey, Map<String,String> certdata, String CSRAlgorithm, String name, KeyFileManager kfm) throws OperatorCreationException, IOException
{
Log.i(LOGCERT, "iniciando generacion de CSR");
this.mensaje(LogType.MENI, "Se a iniciado la generacion de un CSR");
ContentSigner signer = new JcaContentSignerBuilder(CSRAlgorithm).build(key);
X500NameBuilder namebuilder = new X500NameBuilder(X500Name.getDefaultStyle());
namebuilder.addRDN(BCStyle.CN, certdata.get("CN"));
namebuilder.addRDN(BCStyle.OU, certdata.get("OU"));
namebuilder.addRDN(BCStyle.O, certdata.get("O"));
namebuilder.addRDN(BCStyle.L, certdata.get("L"));
namebuilder.addRDN(BCStyle.ST, certdata.get("ST"));
namebuilder.addRDN(BCStyle.C, certdata.get("C"));
namebuilder.addRDN(BCStyle.EmailAddress, certdata.get("EMAIL"));
namebuilder.addRDN(new ASN1ObjectIdentifier("2.5.4.45"), certdata.get("RIFCI"));
namebuilder.addRDN(new ASN1ObjectIdentifier("2.5.4.23"), certdata.get("FAX"));
PKCS10CertificationRequestBuilder csrbuilder = new JcaPKCS10CertificationRequestBuilder(namebuilder.build(),pkey);
PKCS10CertificationRequest csr = csrbuilder.build(signer);
if(kfm.salvarLlave(csr.getEncoded(), KeyFileManager.CSRFILE, name)){
Log.i(LOGCERT, "CSR Almacenado");
return csr;
}
else{
Log.i(LOGCERT, "CSR no almacenado");
return csr;
}
}

关于java - 将属性放入 X500Name Builder Bouncy CaSTLe 以生成 PKCS10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19861568/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com