2011-12-25 79 views
2

如何打印存儲在BIO對象「time」中的值。基本上我需要提取簽名的時間。如何在opensl中打印BIO對象或從ASN1_TYPE對象打印時間

ASN1_TYPE *asn1obj;   
if (!(asn1obj = PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime))) { 
    NSLog(@"Failed to retireve the signing time"); 
}else{ 
    if (asn1obj->type == V_ASN1_UTCTIME) { 
     BIO * time = data=BIO_new(BIO_s_bio()); 
     i = ASN1_UTCTIME_print(time,asn1obj->value.utctime); 
     NSLog(@"return value from ASN1_UTCTIME_print %d ",i);     
    } 
} 

感謝

回答

2

這是如何獲得工作

if (asn1obj->type == V_ASN1_UTCTIME) { 

    NSLog(@"--------------------------->Retireve the signing time"); 
    BIO * time = data=BIO_new(BIO_s_bio());     

    BIO_printf(bio_out,"\n"); 

    i = ASN1_UTCTIME_print(bio_out,asn1obj->value.utctime); //used to display in console 
    i = ASN1_UTCTIME_print(time,asn1obj->value.utctime);  //used to hold in BIO object 

    BIO_printf(bio_out,"\n"); 

    BIO *mem = BIO_new(BIO_s_mem());    
    //pass this mem BIO to hold the data 
    i = ASN1_UTCTIME_print(mem,asn1obj->value.utctime);  //converting asn1 to memory BIO 

    //Extract the BUF_MEM structure from a memory BIO and then free up the BIO: 

    BUF_MEM *bptr; 
    BIO_get_mem_ptr(mem, &bptr);     //converting memory BIO to BUF_MEM 
    BIO_set_close(mem, BIO_NOCLOSE); /* So BIO_free() leaves BUF_MEM alone */ 

    char *buff = (char *)malloc(bptr->length);  //converting BUF_MEM to Char * 
    memcpy(buff, bptr->data, bptr->length-1);   //to be used later 
    buff[bptr->length-1] = 0; 

    NSLog(@"--------------------------->%s",buff);  // this is my 
            // OUTPUT : Apr 5 14:30:53 2012 GM 

    NSLog(@"--------------------------->End"); 
    BIO_free_all(mem);    
} 

希望這有助於:)

+0

而且不使用Generalizedtime ....它的投擲時間,這心不是正確的享受:) – chetan 2012-04-05 15:22:23