Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将(X509)的堆栈_转换为ASN1流_C++_C_Openssl_Asn.1 - Fatal编程技术网

C++ 将(X509)的堆栈_转换为ASN1流

C++ 将(X509)的堆栈_转换为ASN1流,c++,c,openssl,asn.1,C++,C,Openssl,Asn.1,首先:对不起,我的英语不好。我希望你能理解我 我在使用OpenSSL 1.0.2时遇到了一些问题。我有一个包含三个证书的堆栈(X509)对象,我想将该堆栈转换为ASN1对象(如八位字节字符串或任意字符串)。这可能吗?我使用外部asn.1库,而不是OpenSSL-ASN1。所以我需要数据作为无符号字符(原始二进制或DER编码) 我可以通过i2d_X509()将单个证书转换为DER格式。这很好,但我想要完整的堆栈。这是我的目标: myAsn1Data ::= sequence { ...

首先:对不起,我的英语不好。我希望你能理解我

我在使用OpenSSL 1.0.2时遇到了一些问题。我有一个包含三个证书的堆栈(X509)对象,我想将该堆栈转换为ASN1对象(如八位字节字符串或任意字符串)。这可能吗?我使用外部asn.1库,而不是OpenSSL-ASN1。所以我需要数据作为无符号字符(原始二进制或DER编码)

我可以通过i2d_X509()将单个证书转换为DER格式。这很好,但我想要完整的堆栈。这是我的目标:

myAsn1Data ::= sequence {
    ...  -- (some ASN.1 data)
    ...  -- (some ASN.1 data)
    ANY  -- contain the DER encoded STACK_OF(X509)....somehow
}
但这可能是正确的方法(ASN.1语法):

或者像这样:

stackOfX509 ::= SET_OF {
    ANY  -- contain a DER encoded X509 certificate
}
Certificate cert1 = asn1decode(certificatefile);
Certificate cert2 = asn1decode(anothercertificatefile);
Certificate cert3 = asn1decode(yetanothercertificatefile);
CertificateStack stack;
stack.push_back(cert1);
stack.push_back(cert2);
stack.push_back(cert3);
myAsn1Data data = new(myAsn1Data);
data.cert = stack;
data.something = 10;
data.else = 20;
asn1encode(data, outputfile)

我希望有人能帮助我。

人们通常为此做两件事之一

1) “欺骗”!如果证书的DER编码表示可用,但其原始模式不可用,只需使用八位字节字符串来存储字节即可

myAsn1Data ::= SEQUENCE {
    ..., -- (some ASN.1 Data)
    ..., -- (some ASN.1 Data)
    cert [2] OCTET STRING -- (the DER bytes would go in this field)
}
您的应用程序代码的流程如下

myAsn1Data data = new(myAsn1Data);
data.cert = readbytesfromfile(certificatefile);
data.something = 10;
data.else = 20;
asn1encode(data, outputfile)
2) 获取X509证书的原始架构。它应该在某个地方,看起来像7.2节。有了这个,ASN.1编译器将为您创建的源代码应该能够解码证书,允许您将它放在myAsn1Data的实例中

IMPORTS Certificate FROM <ITU's X509 Schema file>

CertificateStack ::= SEQUENCE of Certificate

myAsn1Data ::= SEQUENCE {
    ..., -- (some ASN.1 Data)
    ..., -- (some ASN.1 Data)
    cert [2] CertificateStack
}

这种方法更好,因为它完全定义了“cert”字段实际上是什么。如果您与其他人交换数据,第一种方法就不太好,因为需要告诉他们cert字段实际上是什么

人们通常为此做两件事之一

1) “欺骗”!如果证书的DER编码表示可用,但其原始模式不可用,只需使用八位字节字符串来存储字节即可

myAsn1Data ::= SEQUENCE {
    ..., -- (some ASN.1 Data)
    ..., -- (some ASN.1 Data)
    cert [2] OCTET STRING -- (the DER bytes would go in this field)
}
您的应用程序代码的流程如下

myAsn1Data data = new(myAsn1Data);
data.cert = readbytesfromfile(certificatefile);
data.something = 10;
data.else = 20;
asn1encode(data, outputfile)
2) 获取X509证书的原始架构。它应该在某个地方,看起来像7.2节。有了这个,ASN.1编译器将为您创建的源代码应该能够解码证书,允许您将它放在myAsn1Data的实例中

IMPORTS Certificate FROM <ITU's X509 Schema file>

CertificateStack ::= SEQUENCE of Certificate

myAsn1Data ::= SEQUENCE {
    ..., -- (some ASN.1 Data)
    ..., -- (some ASN.1 Data)
    cert [2] CertificateStack
}

这种方法更好,因为它完全定义了“cert”字段实际上是什么。如果您与其他人交换数据,第一种方法就不太好,因为需要告诉他们cert字段实际上是什么

@SBond,别担心,希望一切顺利。@SBond,别担心,希望一切顺利。