• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一蓑烟雨
C/C++,Linux,语音技术
博客园    首页    新随笔    联系   管理    订阅  订阅
Poco::Crypto--加解密(RSA)

1、简单的加解密

        Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
        std::string val("I love karen!");
        std::string enc = pCipher->encryptString(val);
        std::string dec = pCipher->decryptString(enc);
        std::cout<<"加密后:"<<enc<<std::endl;
        std::cout<<"解密后:"<<dec<<std::endl;

2、用公私钥加解密

        std::istringstream str(anyPem);
        X509Certificate cert(str);
        RSAKey publicKey(cert);
        std::istringstream str2(anyPem);
        RSAKey privateKey(0, &str2, "test");
        Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(publicKey);
        Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(privateKey);
        std::string val("lets do some encryption");

        std::string enc = pCipher->encryptString(val);
        std::string dec = pCipher2->decryptString(enc);
        std::cout<<"加密后:"<<enc<<std::endl;
        std::cout<<"解密后:"<<dec<<std::endl;
posted on 2012-09-04 16:32  lovemu  阅读(3115)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3