使用 Objective-c 将 C 指针的内容存储到文件中

发布于 2024-12-29 21:10:36 字数 288 浏览 0 评论 0原文

我有一个 CMS_ContentInfo 指针...

    CMS_ContentInfo *encryptedDataWithCMS = CMS_encrypt(certList, dataToEncrypt, cipher, NULL);

...我想将 CMS_ContentInfo 存储到一个新的 .p7m 文件中。 有谁知道如何做到这一点?

编辑:此外,我需要将其保存在 Objective-C (NSObject 的任何实例)中。

谢谢, 克里斯

I have a CMS_ContentInfo pointer...

    CMS_ContentInfo *encryptedDataWithCMS = CMS_encrypt(certList, dataToEncrypt, cipher, NULL);

... and I would like to store the CMS_ContentInfo into a new .p7m file.
Does anyone have an idea how to do this?

EDIT: Furthermore I need to save it in objective-c (any instance of NSObject).

Thanks,
Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2025-01-05 21:10:36

不确定这是否是您所要求的,但要编写结构的内容:

void writePtr( CMS_ContentInfo *tehPtr ){

    FILE *tehFile;

    //opens the file you want to write in, please notice the fopen mode "wb".
    tehFile = fopen( "tehFilePath", "wb" );
    //write 1 block of sizeOf( CMS_ContentInfo ) bytes into tehFile with the contents
    //of tehPtr
    fwrite( tehPtr, sizeOf( CMS_ContentInfo ), 1, tehFile );

    fclose( tehFile );

}

CMS_ContentInfo readPtr(){

    FILE *tehFile;
    CMS_ContentInfo *tehPtr;

    //opens the file you want to read from, please notice the fopen mode "rb".
    tehFile = fopen( "tehFilePath", "rb" );
    //allocates tho pointer where the read data will be stored.
    tehPtr = (CMS_ContentInfo *) malloc( sizeOf(CMS_ContentInfo) );

    //reads 1 block of sizeOf( CMS_ContentInfo ) bytes from tehFile into tehPtr
    fread( tehPtr, sizeOf( CMS_ContentInfo ), 1, tehFile );

    fclose( tehFile );

    return tehPtr;

}

Not sure if this is what you are asking, but to write the contents of a structure:

void writePtr( CMS_ContentInfo *tehPtr ){

    FILE *tehFile;

    //opens the file you want to write in, please notice the fopen mode "wb".
    tehFile = fopen( "tehFilePath", "wb" );
    //write 1 block of sizeOf( CMS_ContentInfo ) bytes into tehFile with the contents
    //of tehPtr
    fwrite( tehPtr, sizeOf( CMS_ContentInfo ), 1, tehFile );

    fclose( tehFile );

}

CMS_ContentInfo readPtr(){

    FILE *tehFile;
    CMS_ContentInfo *tehPtr;

    //opens the file you want to read from, please notice the fopen mode "rb".
    tehFile = fopen( "tehFilePath", "rb" );
    //allocates tho pointer where the read data will be stored.
    tehPtr = (CMS_ContentInfo *) malloc( sizeOf(CMS_ContentInfo) );

    //reads 1 block of sizeOf( CMS_ContentInfo ) bytes from tehFile into tehPtr
    fread( tehPtr, sizeOf( CMS_ContentInfo ), 1, tehFile );

    fclose( tehFile );

    return tehPtr;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文