bouncycastle中,我可以从KeyUsage创建一个DEROctetString。

那如何从DEROctetString开始获取KeyUsage?

例:

DEROctetString derString = new DEROctetString(new KeyUsage(KeyUsage.digitalSignature));
KeyUsage ku = ...(some code to get back KeyUsage starting from derString)...


我需要这样做是因为我能够使用KeyUsage扩展请求创建证书请求,但是,仅凭证书请求,我就无法取回KeyUsage扩展。

最佳答案

我找到了使用ASN1InputStream的解决方案:

ASN1InputStream ais = new ASN1InputStream(derOctetString.getOctetStream());
KeyUsage ku = new KeyUsage((DERBitString) ais.readObject());


这样可行!

10-08 15:54