如何在签约bouncyCastle之前添加ASN.1扩展? [英] How to add ASN.1 extensions before signing with bouncycastle?

查看:43
本文介绍了如何在签约bouncyCastle之前添加ASN.1扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,所以我完全被难住了。通常,当我签署证书时,我会使用如下所示的ASN.1来指定特定规则,例如,可以用于物联网。

1.2.3.4=ASN1:SEQUENCE:seq_sect

[seq_sect]
one=SEQUENCE:do_one
two=SEQUENCE:do_two

[do_one]
field.1 = UTF8:field1/*
field.2 = UTF8:field2/*

[do_two]
field.1 = UTF8:field1/*
field.2 = UTF8:field2/*

我通常使用一个名为xca的程序,但在这种情况下,我一直在使用bouncyCastle编码,并且在将其导入到X509v3certifateBuilder中时一直非常困难。我知道我应该使用.addExtension,但我不是特别确定是否应该将规则存储在.txt文件中,或者是否应该将其存储在数组中并以某种方式解析它?

推荐答案

实际上您使用的是xca包装的openssl。只有OpenSSL对ASN.1使用这种特定的基于文本的"配置"格式。对于BouncyCastle,您必须改为编写类似于(未测试)的代码:

ASN1EncodableVector one = new ASN1EncodableVector();
one.add(new DERUTF8String("field1/*"));
one.add(new DERUTF8String("field2/*"));

// if two is really identical to one, just reuse it; otherwise do something different

ASN1EncodableVector outer = new ASN1EncodableVector();
outer.add(new DERSequence(one));
outer.add(new DERSequence(two)); // or one again

builder.addExtension (oid, critical, new DERSequence(outer));

相似How to add PrivateKeyUsage extension to a certificate using bouncycastle in java?Creating Custom X509 v3 Extensions in Java with Bouncy Castle

这篇关于如何在签约bouncyCastle之前添加ASN.1扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆