//获取证书主题信息
subject = X509_get_subject_name(cert);
//获得证书主题信息条目个数
entriesNum = sk_X509_NAME_ENTRY_num(subject->entries);
//X509_NAME_print_ex(biosubject, subject, 0, ASN1_STRFLGS_ESC_MSB);
//BIO_read(biosubject,msginfo,msginfoLen);
//循环读取个条目信息
for(i=0;i<entriesNum;i++)
{
//获取第I个条目值
name_entry = sk_X509_NAME_ENTRY_value(subject->entries,i);
Nid = OBJ_obj2nid(name_entry->object);
out=NULL;
if((len = ASN1_STRING_to_UTF8(&out,name_entry->value))<0)
continue;
nUtf8 = 2*len;
pUtf8 = (unsigned short *)malloc(nUtf8);
memset(pUtf8,0,nUtf8);
rv = MultiByteToWideChar(
CP_UTF8,
0,
(char*)out,
len,
pUtf8,
nUtf8);
rv = WideCharToMultiByte(
CP_ACP,
0,
pUtf8,
rv,
(char*)msginfo,
nUtf8,
NULL,
NULL);
free(pUtf8);
OPENSSL_free(out);
pUtf8 = NULL;
msginfoLen = rv;
msginfo[msginfoLen]='\0';
switch(Nid)
{
case NID_countryName://国家
printf("subject 's countryName:%s\n",msginfo);
break;
case NID_stateOrProvinceName://省
printf("subject 's ProvinceName:%s\n",msginfo);
break;
case NID_localityName://地区
printf("subject 's localityName:%s\n",msginfo);
break;
case NID_organizationName://组织
printf("subject 's organizationName:%s\n",msginfo);
break;
case NID_organizationalUnitName://单位
printf("subject 's organizationalUnitName:%s\n",msginfo);
break;
case NID_commonName://通用名
printf("subject 's commonName:%s\n",msginfo);
break;
case NID_pkcs9_emailAddress://Mail
printf("subject 's emailAddress:%s\n",msginfo);
break;
}//end switch
}
posted on 2008-12-10 10:25
黄剑父 阅读(2300)
评论(0) 编辑 收藏 引用 所属分类:
OPEN SSL