gpt4 book ai didi

openssl - 如何在 opensl 中打印 BIO 对象或从 ASN1_TYPE 对象打印时间

转载 作者:行者123 更新时间:2023-12-04 06:03:50 25 4
gpt4 key购买 nike

如何打印存储在 BIO 对象“时间”中的值。基本上我需要提取签名时间。

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);
}
}

谢谢

最佳答案

这就是它的工作方式

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);
}

希望这可以帮助 :)

关于openssl - 如何在 opensl 中打印 BIO 对象或从 ASN1_TYPE 对象打印时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8630300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com