当前位置: 首页>>代码示例>>C++>>正文


C++ Sign::initPublicKey方法代码示例

本文整理汇总了C++中Sign::initPublicKey方法的典型用法代码示例。如果您正苦于以下问题:C++ Sign::initPublicKey方法的具体用法?C++ Sign::initPublicKey怎么用?C++ Sign::initPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sign的用法示例。


在下文中一共展示了Sign::initPublicKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mainCryptopp


//.........这里部分代码省略.........
        int maxinlen = Base16::getPlainLen(outlen);
        printf("maxinlen=%d\n", maxinlen);
        char * orgdata = new char[maxinlen];
        int orglen = Base16::decode(outdata, outlen, orgdata);
        printf("orglen=%d\n", orglen);
        printf("orgdata(hex)=");
        dump(orgdata, orglen);

        delete[] outdata;
        delete[] outstr;
        delete[] orgdata;
    }

    // RSA testing.
    {
        printf("\n=======================RSA PKCS #1=====================\n");
        // key
        // N factor in RSA, aslo called modulus.
        const char * N = "90755611487566208138950675092879865387596685014726501531250157258482495478524769456222913843665634824684037468817980814231054856125127115894189385717148934026931120932481402379431731629550862846041784305274651476086892165805223719552575599962253392248079811268061946102234935422772131475340988882825043233323";
        // e factor in RSA, aslo called public exponent.
        const char * e = "65537";
        // d factor in RSA, aslo called private exponent
        const char * d = "17790520481266507102264359414044396762660094486842415203197747383916331528947124726552875080482359744765793816651732601742929364124685415229452844016482477236658413327331659722342187036963943428678684677279032263501011143882814728160215380051287503219732737197808611144507720521201393129692996926599975297921";

        // input data.
        const char * indata = "bsmith is a good guy.";
        int inlen = (int)strlen(indata);
        printf("inlen=%d\n", inlen);
        printf("indata(hex)=");
        dump(indata, inlen);

        // init RSA public key encryptor.
        RSA enc;
        enc.initPublicKey(N, e);

        // encrypt.
        int maxoutlen = enc.getCipherLen(inlen);
        printf("maxoutlen=%d\n", maxoutlen);
        char * outdata = new char[maxoutlen];
        int outlen = enc.encrypt(indata, inlen, outdata);
        printf("outlen=%d\n", outlen);
        printf("outdata(hex)=");
        dump(outdata, outlen);

        // init private for RSA decryptor.
        RSA dec;
        dec.initPrivateKey(N, e, d);

        // decrypt.
        int maxinlen = dec.getPlainLen(outlen);
        printf("maxinlen=%d\n", maxinlen);
        char * orgdata = new char[maxinlen];
        int orglen = dec.decrypt(outdata, outlen, orgdata);
        printf("orglen=%d\n", orglen);
        printf("orgdata(hex)=");
        dump(orgdata, orglen);

        delete[] outdata;
        delete[] orgdata;
    }

    // AES/CBC/PKCS5Padding testing.
    {
        printf("\n=======================AES/CBC/PKCS5Padding=====================\n");
        // key
        const char * key = "0123456789abcdef";
开发者ID:XClouded,项目名称:aes-rsa-cpp-java,代码行数:67,代码来源:test.cpp


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