[BouncyCastle] PKCS10CertificationRequest.getEncoded()返回什么编码?

时间:2021-03-23 18:24:24

Does it return DER encoded data, or some other format?

它是否返回DER编码数据或其他格式?

The Javadoc I've been able to find leaves something to be desired details-wise...

Javadoc我已经能够找到一些有待细节的东西......

1 个解决方案

#1


2  

Well, despite the fact that someone has seen fit to down-vote the question, I'll post the answer here for posterity.

好吧,尽管有人认为这个问题适合投票,但我会在这里为后人发布答案。

At least for v1.52, org.bouncycastle.pkcs.PKCS10CertificationRequest#getEncoded() is implemented as:

至少对于v1.52,org.bouncycastle.pkcs.PKCS10CertificationRequest#getEncoded()实现为:

public byte[] More ...getEncoded()
    throws IOException
{
    return certificationRequest.getEncoded();
}

This calls org.bouncycastle.asn1.pkcs.CertificationRequest#getEncoded(), which results in the inherited method org.bouncycastle.asn1.ASN1Object#getEncoded(). This method actually has some Javadoc, and it states "Return the default BER or DER encoding for this object".

这将调用org.bouncycastle.asn1.pkcs.CertificationRequest#getEncoded(),这将导致继承的方法org.bouncycastle.asn1.ASN1Object#getEncoded()。这个方法实际上有一些Javadoc,它声明“返回此对象的默认BER或DER编码”。

I wasn't completely sure whether this guarantees DER encoding, so I did the following:

我不完全确定这是否保证DER编码,所以我做了以下事情:

private byte[] makeDEREncodedRequest(final PKCS10CertificationRequest request) {
    try {
        return request.toASN1Structure().getEncoded(ASN1Encoding.DER);
    } catch (IOException e) {
        // ... <Exception handling code> ...
    }
}

#1


2  

Well, despite the fact that someone has seen fit to down-vote the question, I'll post the answer here for posterity.

好吧,尽管有人认为这个问题适合投票,但我会在这里为后人发布答案。

At least for v1.52, org.bouncycastle.pkcs.PKCS10CertificationRequest#getEncoded() is implemented as:

至少对于v1.52,org.bouncycastle.pkcs.PKCS10CertificationRequest#getEncoded()实现为:

public byte[] More ...getEncoded()
    throws IOException
{
    return certificationRequest.getEncoded();
}

This calls org.bouncycastle.asn1.pkcs.CertificationRequest#getEncoded(), which results in the inherited method org.bouncycastle.asn1.ASN1Object#getEncoded(). This method actually has some Javadoc, and it states "Return the default BER or DER encoding for this object".

这将调用org.bouncycastle.asn1.pkcs.CertificationRequest#getEncoded(),这将导致继承的方法org.bouncycastle.asn1.ASN1Object#getEncoded()。这个方法实际上有一些Javadoc,它声明“返回此对象的默认BER或DER编码”。

I wasn't completely sure whether this guarantees DER encoding, so I did the following:

我不完全确定这是否保证DER编码,所以我做了以下事情:

private byte[] makeDEREncodedRequest(final PKCS10CertificationRequest request) {
    try {
        return request.toASN1Structure().getEncoded(ASN1Encoding.DER);
    } catch (IOException e) {
        // ... <Exception handling code> ...
    }
}