作者在 2009-07-28 20:16:15 发布以下内容
#include "stdafx.h"
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#pragma comment(lib,"libeay32.lib")
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#pragma comment(lib,"libeay32.lib")
/*
CardID ::= SEQUENCE {
version Version DEFAULT v1,
vendor VENDOR,
guids GUIDS }
CardID ::= SEQUENCE {
version Version DEFAULT v1,
vendor VENDOR,
guids GUIDS }
Version ::= INTEGER {v1(0), v2(1), v3(2)}
VENDOR ::= IA5STRING(SIZE(0..8))
GUID ::= OCTET STRING(SIZE(16))
GUIDS ::= SEQUENCE OF GUID
*/
VENDOR ::= IA5STRING(SIZE(0..8))
GUID ::= OCTET STRING(SIZE(16))
GUIDS ::= SEQUENCE OF GUID
*/
typedef struct
{
ASN1_INTEGER *Version;
ASN1_IA5STRING *VENDOR;
STACK_OF(ASN1_OCTET_STRING) *GUIDS;
} DER_CARD_ID;
ASN1_ITEM_TEMPLATE(GUIDS);
{
ASN1_INTEGER *Version;
ASN1_IA5STRING *VENDOR;
STACK_OF(ASN1_OCTET_STRING) *GUIDS;
} DER_CARD_ID;
ASN1_ITEM_TEMPLATE(GUIDS);
ASN1_SEQUENCE(DER_CARD_ID) = {
ASN1_SIMPLE(DER_CARD_ID, Version, ASN1_INTEGER),
ASN1_SIMPLE(DER_CARD_ID, VENDOR, ASN1_IA5STRING),
ASN1_SEQUENCE_OF(DER_CARD_ID, GUIDS, ASN1_OCTET_STRING)
} ASN1_SEQUENCE_END(DER_CARD_ID);
ASN1_SIMPLE(DER_CARD_ID, Version, ASN1_INTEGER),
ASN1_SIMPLE(DER_CARD_ID, VENDOR, ASN1_IA5STRING),
ASN1_SEQUENCE_OF(DER_CARD_ID, GUIDS, ASN1_OCTET_STRING)
} ASN1_SEQUENCE_END(DER_CARD_ID);
IMPLEMENT_ASN1_FUNCTIONS(DER_CARD_ID)
int main(int argc, char* argv[])
{
printf("Hello World!\n");
{
printf("Hello World!\n");
DER_CARD_ID *p = DER_CARD_ID_new();
ASN1_INTEGER_set(p->Version,0);
ASN1_STRING_set(p->VENDOR,"MSFT", -1);
unsigned char out[1024] = {0};
int nOutLen = 0;
unsigned char *pout = out;
ASN1_OCTET_STRING *pStr = ASN1_OCTET_STRING_new();
ASN1_STRING_set(pStr,"1111111111111111", 16);
sk_push(p->GUIDS,(char *)pStr);
pStr = ASN1_OCTET_STRING_new();
ASN1_STRING_set(pStr,"2222222222222222", 16);
sk_push(p->GUIDS,(char *)pStr);
nOutLen = i2d_DER_CARD_ID(p,&pout);
DER_CARD_ID_free(p);
return 0;
}
ASN1_INTEGER_set(p->Version,0);
ASN1_STRING_set(p->VENDOR,"MSFT", -1);
unsigned char out[1024] = {0};
int nOutLen = 0;
unsigned char *pout = out;
ASN1_OCTET_STRING *pStr = ASN1_OCTET_STRING_new();
ASN1_STRING_set(pStr,"1111111111111111", 16);
sk_push(p->GUIDS,(char *)pStr);
pStr = ASN1_OCTET_STRING_new();
ASN1_STRING_set(pStr,"2222222222222222", 16);
sk_push(p->GUIDS,(char *)pStr);
nOutLen = i2d_DER_CARD_ID(p,&pout);
DER_CARD_ID_free(p);
return 0;
}