c++ poco rsa 加密 java,Poco::Crypto--加解密(AES)

67d0865f17d9be527254bf8a8ff6c5b4.gif

1 int main(const std::vector<:string>& args)

2 {

3 /*TO DO*/

4 Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));

5

6 std::string in("I love karen!");

7 std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);

8 std::string result = pCipher->decryptString(out, Cipher::ENC_BASE64);

9 std::cout<

10 std::cout<

11

12 return Application::EXIT_OK;

13 }

67d0865f17d9be527254bf8a8ff6c5b4.gif

1、第4行代码,创建一个256位的AES加密算法;

2、第7、8行代码,分别实现加密与解密过程。

3、在加密与解密过程中,代码中使用了BASE64编码方式,另外在POCO::Crypto中还有以下编码方式:

enum Encoding

/// Transport encoding to use for encryptString() and decryptString().

{

ENC_NONE = 0x00, /// Plain binary output

ENC_BASE64 = 0x01, /// Base64-encoded output

ENC_BINHEX = 0x02, /// BinHex-encoded output

ENC_BASE64_NO_LF = 0x81, /// Base64-encoded output, no linefeeds

ENC_BINHEX_NO_LF = 0x82, /// BinHex-encoded output, no linefeeds

};

67d0865f17d9be527254bf8a8ff6c5b4.gif

1 int main(const std::vector<:string>& args)

2 {

3 /*TO DO*/

4 Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));

5

6 static const std::string SECRET_MESSAGE = "This is a secret message. Don't tell anyone.";

7

8 std::stringstream sstr;

9 EncryptingOutputStream encryptor(sstr, *pCipher);

10 encryptor << SECRET_MESSAGE;

11 encryptor.close();

12

13 DecryptingInputStream decryptor(sstr, *pCipher);

14 std::string iresult;

15 Poco::StreamCopier::copyToString(decryptor, iresult);

16

17 std::cout<

18 return Application::EXIT_OK;

19 }

67d0865f17d9be527254bf8a8ff6c5b4.gif

1、第6行,为原文;

2、第9行,加密;第13行,解密;

3、第15行,得到解密结果,就是原文了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值