openssl解析国密X509证书,把公钥拿出来重写一下就行了
x = strToX509(pbCert, pulCertLen);
dwRet = getCertPubKey(x, &pRSAPubKeyBlob, &pECCPubKeyBlob);
ECCPUBLICKEYBLOB pec = { 0 };//目标公钥
pec.BitLen = 256;
int i = 0;
for (i = 0; i < 64; i++){
if (i <= 31){
pec.XCoordinate[i] = 0;
pec.YCoordinate[i] = 0;
}
else{
pec.XCoordinate[i] = pECCPubKeyBlob.XCoordinate[i - 32];
pec.YCoordinate[i] = pECCPubKeyBlob.YCoordinate[i - 32];
}
}
其实就是公钥结构解析的问题,SM2公钥所需要的格式和X509解析出来的X,Y位置是颠倒的,要求的结果是X,Y数组前32为0;而X509提供的为后32为0,正好颠倒了。