我正在尝试使用phpseclib ASN1.php,我有如下所示的地图;
$IdentityObjectMap = array('type' =>FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'identityIdentificationData' => array('type'=>FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'version' => array('type' => FILE_ASN1_TYPE_IA5_STRING),
'staticData' =>array('type' => FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'acceptedPolicyVersion' => array('type' =>FILE_ASN1_TYPE_IA5_STRING),
'cardHolderID' => array('type' =>FILE_ASN1_TYPE_INTEGER),
'deviceSerialNumber' => array('type' => FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'deviceType' => array('type' =>FILE_ASN1_TYPE_INTEGER),
'deviceUniqueID' => array('type' =>FILE_ASN1_TYPE_OCTET_STRING)
),
),
'appLabel' => array('type' =>FILE_ASN1_TYPE_UTF8_STRING),
'requestorRole' => array('type' => FILE_ASN1_TYPE_ENUMERATED,
'roleClient'=> array('mapping' =>0),
'roleParticipant' =>array('mapping' =>1)
),
'creationTime' => array('type' =>FILE_ASN1_TYPE_UTC_TIME)
)
)
)
)
)
);我有一个json,并使用json_decode(IdentityObject,true)来绘制这张地图,如下所示;
杰森:
{
\"identityIdentificationData\":{
\"version\":\"2.0\",
\"staticData\":{
\"acceptedPolicyVersion\":\"2\",
\"cardHolderID\":11111111111,
\"deviceSerialNumber\":{
\"deviceType\":3,
\"deviceUniqueID\":\"11111111\"
},
\"appLabel\":\"examination\",
\"requestorRole\": \"roleClient\",
\"creationTime\": \"180319141236Z\"
}
}
}";这个jsons输出数组:
array
'identityIdentificationData' =>
array
'version' => '2.0'
'staticData' =>
array
'acceptedPolicyVersion' => '2'
'cardHolderID' => 11111111111
'deviceSerialNumber' =>
array
'deviceType' => 3
'deviceUniqueID' => '11111111'
'appLabel' => 'examination'
'requestorRole' => 'roleClient'
'creationTime' => '180319141236Z' 这个数组应该是什么结构,我可以成功编译。
给出此错误的最终代码
Undefined index: children .../ASN1.php on line 950.最终代码:
$asn1->encodeDER($IdentityObject,$IdentityObjectMap);发布于 2018-03-22 12:38:18
在File/X509.php中只有一种枚举类型,并且它是这样定义的:
$this->CRLReason = array('type' => FILE_ASN1_TYPE_ENUMERATED,
'mapping' => array(
'unspecified',
'keyCompromise',
'cACompromise',
'affiliationChanged',
'superseded',
'cessationOfOperation',
'certificateHold',
// Value 7 is not used.
8 => 'removeFromCRL',
'privilegeWithdrawn',
'aACompromise'
)
);枚举类型定义不包括映射键。这可能就是你所需要的。例如:
'requestorRole' => array('type' => FILE_ASN1_TYPE_ENUMERATED,
'mapping' => array(
'roleClient',
'roleParticipant'
)
),也就是说,您使用的是什么版本的phpseclib?我用1.0.10 (我想)尝试了您的代码,得到了一个与您报告的错误不同的错误:
Fatal error: Uncaught Error: Call to a member function toBytes() on string当我使用可选定义的requestorRole定义时,我得到了以下错误消息:
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (180319141236Z) at position 11 (6)通过将'creationTime' => '180319141236Z'替换为'creationTime': 'January 1, 2018',我能够修复最后一个错误。180319141236Z更接近X.509证书使用的格式,但是phpseclib在通过DateTime或strtotime (每个https://github.com/phpseclib/phpseclib/blob/1.0.10/phpseclib/File/X509.php#L3420)运行该值并对其进行适当格式化之后,自己生成该值。如果你想直接设置它,你自己,看看这个:
https://github.com/phpseclib/phpseclib/blob/1.0.10/phpseclib/File/X509.php#L3952
这是我的密码:
https://stackoverflow.com/questions/49421661
复制相似问题