• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript asn1js.fromBER函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中asn1js.fromBER函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromBER函数的具体用法?TypeScript fromBER怎么用?TypeScript fromBER使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fromBER函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: verifyCMSSigned

// *********************************************************************************
// endregion 
// *********************************************************************************
// region Verify existing CMS_Signed
// *********************************************************************************
function verifyCMSSigned() {
    // region Initial check 
    if (cmsSignedBuffer.byteLength === 0) {
        alert("Nothing to verify!");
        return;
    }
    // endregion 

    // region Decode existing CMS_Signed  
    const asn1 = asn1js.fromBER(cmsSignedBuffer);
    const cmsContentSimpl = new ContentInfo({ schema: asn1.result });
    const cmsSignedSimpl = new SignedData({ schema: cmsContentSimpl.content });
    // endregion 

    // region Verify CMS_Signed  
    cmsSignedSimpl.verify({ signer: 0, trustedCerts: trustedCertificates }).
        then(
        result => alert(`Verification result: ${result}`),
        error => alert(`Error during verification: ${error}`)
        );
    // endregion 
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:27,代码来源:pkijs-tests.ts


示例2: parseCAbundle

// *********************************************************************************
// endregion
// *********************************************************************************
// region Parse "CA Bundle" file
// *********************************************************************************
function parseCAbundle(buffer: ArrayBuffer) {
    // region Initial variables
    const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    const startChars = "-----BEGIN CERTIFICATE-----";
    const endChars = "-----END CERTIFICATE-----";
    const endLineChars = "\r\n";

    const view = new Uint8Array(buffer);

    let waitForStart = false;
    let middleStage = true;
    let waitForEnd = false;
    let waitForEndLine = false;
    let started = false;

    let certBodyEncoded = "";
    // endregion

    for (let i = 0; i < view.length; i++) {
        if (started === true) {
            if (base64Chars.indexOf(String.fromCharCode(view[i])) !== (-1))
                certBodyEncoded = certBodyEncoded + String.fromCharCode(view[i]);
            else {
                if (String.fromCharCode(view[i]) === "-") {
                    // region Decoded trustedCertificates
                    const asn1 = asn1js.fromBER(stringToArrayBuffer(window.atob(certBodyEncoded)));
                    try {
                        trustedCertificates.push(new Certificate({ schema: asn1.result }));
                    }
                    catch (ex) {
                        alert("Wrong certificate format");
                        return;
                    }
                    // endregion

                    // region Set all "flag variables"
                    certBodyEncoded = "";

                    started = false;
                    waitForEnd = true;
                    // endregion
                }
            }
        }
        else {
            if (waitForEndLine === true) {
                if (endLineChars.indexOf(String.fromCharCode(view[i])) === (-1)) {
                    waitForEndLine = false;

                    if (waitForEnd === true) {
                        waitForEnd = false;
                        middleStage = true;
                    }
                    else {
                        if (waitForStart === true) {
                            waitForStart = false;
                            started = true;

                            certBodyEncoded = certBodyEncoded + String.fromCharCode(view[i]);
                        }
                        else
                            middleStage = true;
                    }
                }
            }
            else {
                if (middleStage === true) {
                    if (String.fromCharCode(view[i]) === "-") {
                        if ((i === 0) ||
                            ((String.fromCharCode(view[i - 1]) === "\r") ||
                                (String.fromCharCode(view[i - 1]) === "\n"))) {
                            middleStage = false;
                            waitForStart = true;
                        }
                    }
                }
                else {
                    if (waitForStart === true) {
                        if (startChars.indexOf(String.fromCharCode(view[i])) === (-1))
                            waitForEndLine = true;
                    }
                    else {
                        if (waitForEnd === true) {
                            if (endChars.indexOf(String.fromCharCode(view[i])) === (-1))
                                waitForEndLine = true;
                        }
                    }
                }
            }
        }
    }
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:98,代码来源:pkijs-tests.ts


示例3: parseCMSSigned

export function parseCMSSigned() {
    // region Initial check
    if (cmsSignedBuffer.byteLength === 0) {
        alert("Nothing to parse!");
        return;
    }
    // endregion

    // region Initial activities
    document.getElementById("cms-dgst-algos").innerHTML = "";

    document.getElementById("cms-certs").style.display = "none";
    document.getElementById("cms-crls").style.display = "none";

    const certificatesTable = document.getElementById("cms-certificates") as HTMLTableElement;
    while (certificatesTable.rows.length > 1)
        certificatesTable.deleteRow(certificatesTable.rows.length - 1);

    const crlsTable = document.getElementById("cms-rev-lists") as HTMLTableElement;
    while (crlsTable.rows.length > 1)
        crlsTable.deleteRow(crlsTable.rows.length - 1);
    // endregion

    // region Decode existing CMS Signed Data
    const asn1 = asn1js.fromBER(cmsSignedBuffer);
    const cmsContentSimpl = new ContentInfo({ schema: asn1.result });
    const cmsSignedSimpl = new SignedData({ schema: cmsContentSimpl.content });
    // endregion

    // region Put information about digest algorithms in the CMS Signed Data
    const dgstmap: { [oid: string]: string } = {
        "1.3.14.3.2.26": "SHA-1",
        "2.16.840.1.101.3.4.2.1": "SHA-256",
        "2.16.840.1.101.3.4.2.2": "SHA-384",
        "2.16.840.1.101.3.4.2.3": "SHA-512"
    };

    for (let i = 0; i < cmsSignedSimpl.digestAlgorithms.length; i++) {
        let typeval = dgstmap[cmsSignedSimpl.digestAlgorithms[i].algorithmId];
        if (typeof typeval === "undefined")
            typeval = cmsSignedSimpl.digestAlgorithms[i].algorithmId;

        const ulrow = `<li><p><span>${typeval}</span></p></li>`;

        document.getElementById("cms-dgst-algos").innerHTML = document.getElementById("cms-dgst-algos").innerHTML + ulrow;
    }
    // endregion

    // region Put information about encapsulated content type
    const contypemap: { [oid: string]: string } = {
        "1.3.6.1.4.1.311.2.1.4": "Authenticode signing information",
        "1.2.840.113549.1.7.1": "Data content"
    };

    let eContentType = contypemap[cmsSignedSimpl.encapContentInfo.eContentType];
    if (typeof eContentType === "undefined")
        eContentType = cmsSignedSimpl.encapContentInfo.eContentType;

    document.getElementById("cms-encap-type").innerHTML = eContentType;
    // endregion

    // region Put information about included certificates
    const rdnmap: { [oid: string]: string } = {
        "2.5.4.6": "C",
        "2.5.4.10": "OU",
        "2.5.4.11": "O",
        "2.5.4.3": "CN",
        "2.5.4.7": "L",
        "2.5.4.8": "S",
        "2.5.4.12": "T",
        "2.5.4.42": "GN",
        "2.5.4.43": "I",
        "2.5.4.4": "SN",
        "1.2.840.113549.1.9.1": "E-mail"
    };

    if ("certificates" in cmsSignedSimpl) {
        for (let cert of cmsSignedSimpl.certificates) {
            if (cert instanceof Certificate) {
                let ul = "<ul>";
                for (let i = 0; i < cert.issuer.typesAndValues.length; i++) {
                    let typeval = rdnmap[cert.issuer.typesAndValues[i].type.toString()];
                    if (typeof typeval === "undefined")
                        typeval = cert.issuer.typesAndValues[i].type.toString();

                    const subjval = cert.issuer.typesAndValues[i].value.valueBlock.value;
                    const ulrow = `<li><p><span>${typeval}</span> ${subjval}</p></li>`;

                    ul = ul + ulrow;
                }

                ul = `${ul}</ul>`;

                const row = certificatesTable.insertRow(certificatesTable.rows.length);
                const cell0 = row.insertCell(0);
                cell0.innerHTML = bufferToHexCodes(cert.serialNumber.valueBlock.valueHex);
                const cell1 = row.insertCell(1);
                cell1.innerHTML = ul;
            }
        }
//.........这里部分代码省略.........
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:101,代码来源:pkijs-tests.ts



注:本文中的asn1js.fromBER函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript aspect.js类代码示例发布时间:2022-05-25
下一篇:
TypeScript ascii-art.image函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap