日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

C++11S/MIME:具有安全功能的簡(jiǎn)單MIME解析器和生成器

 碼農(nóng)9527 2021-05-12

    這是我的簡(jiǎn)單MIME解析器和生成器的版本2,該版本使用C++11元素和Win32API進(jìn)行快速處理。

    對(duì)于S/MIME,庫(kù)現(xiàn)在使用我的AdES。

    從此處包括QP解碼器。

    單個(gè)消息生成器

// Single MessageMIME2::CONTENT c;

c["MIME-Version"] = "1.0";
c["Content-Type"] = "text/plain";
c.SetData("Hello");auto str = c.SerializeToVector();12345678復(fù)制代碼類型:[cpp]

    結(jié)果:

MIME-Version: 1.0Content-Type: text/plain

Hello1234復(fù)制代碼類型:[cpp]

    一些二進(jìn)制消息

MIME2::CONTENT c;
c["MIME-Version"] = "1.0";
c["Content-Type"] = "application/octet-stream";
c["Content-Transfer-Encoding"] = "base64";
c["Content-Disposition"] = "attachment; filename=\"hello.txt\"";string out = MIME2::Char2Base64("Hello", 5);
c.SetData(out.c_str());auto str = c.SerializeToVector();123456789復(fù)制代碼類型:[cpp]

    結(jié)果:

MIME-Version: 1.0Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="hello.txt"SGVsbG8=123456復(fù)制代碼類型:[cpp]

    多部分生成器

MIME2::CONTENTBUILDER cb;
MIME2::CONTENT e1;
MIME2::CONTENT e2;
e1["Content-Type"] = "text/plain";
e1.SetData("Hello\r\n\r\n");
e2["Content-Type"] = "text/html";
e2.SetData("<b>Hello</b>");

cb.Add(e1);
cb.Add(e2);

MIME2::CONTENT cc;
cb.Build(cc, "multipart/alternative");auto str = cc.SerializeToVector();123456789101112131415復(fù)制代碼類型:[cpp]

    結(jié)果:

MIME-Version: 1.0Content-Type: multipart/alternative; boundary="{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}"--{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}
Content-Type: text/plain

Hello

--{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}
Content-Type: text/html

<b>Hello</b>

--{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}--1234567891011121314復(fù)制代碼類型:[cpp]

簡(jiǎn)單解析

string str = 
R"(MIME-Version: 1.0
Content-Type: text/plain

Hello)";

    MIME2::CONTENT c;    if (c.Parse(str.c_str()) != MIME2::MIMEERR::OK)        return;    auto a1 = c.hval("Content-Type"); // a1 = "text/plain"
    auto a2 = c.GetData(); // vector<char> with the data123456789101112復(fù)制代碼類型:[cpp]

    解析多個(gè)

string str = "MIME-Version: 1.0\r\nContent-Type: multipart/alternative; boundary=\"{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}\"\r\n\r\n\r\n--{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}\r\nContent-Type: text/plain\r\n\r\nHello\r\n\r\n--{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}\r\nContent-Type: text/html\r\n\r\n<b>Hello</b>\r\n\r\n--{79EAC9E2-BAF9-11CE-8C82-00AA004BA90B}--";

    MIME2::CONTENT c;    if (c.Parse(str.c_str()) != MIME2::MIMEERR::OK)        return;    auto a1 = c.hval("Content-Type","boundary"); // a1 = the boundary
    if (a1.empty())        return;    vector<MIME2::CONTENT> Contents;
    MIMELIB::ParseMultipleContent(str.c_str(), a1.c_str(), Contents);    // Should have 2
    vector<char> d;
    Contents[1].DecodeData(d); // Decodes from Base64 or Quoted-Printable
    // d = "<b>Hello</b>"123456789101112131415161718192021222324252627282930復(fù)制代碼類型:[cpp]

    S/MIME

    對(duì)于S/MIME,該庫(kù)現(xiàn)在使用AdES。您必須#defineMIME_CMS使用S/MIME。

MIMEERR Encrypt(CONTENT& c, std::vector<PCCERT_CONTEXT> certs, bool BinaryOutput = false);MIMEERR Decrypt(CONTENT& c);MIMEERR Sign(CONTENT& co, std::vector<PCCERT_CONTEXT> certs,      std::vector<PCCERT_CONTEXT> addcerts, const wchar_t* TimeStampServer = 0,      bool Attached = true, bool BinaryOutput = false);MIMEERR Verify(vector<PCCERT_CONTEXT>* Certs = 0, AdES::CLEVEL* plev = 0);123456復(fù)制代碼類型:[cpp]

    HTTP支持

vector<char> data = "HTTP 1/1 200 OK\r\n...."c.Parse(data.data(),true); // true indicates a possible HTTP headerauto mh = c1.httphdr();    // Gets the header123復(fù)制代碼類型:[java]

    或建立:

c.AddHTTPHeader("HTTP 1/1 200 OK");

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約