使用Botan進行RSA公有金鑰加密
阿新 • • 發佈:2019-02-18
void MainWindow::testRSAPublicKeyEncode() { using Botan::byte; using Botan::Public_Key; using Botan::PK_Encryptor_EME; constexpr byte pemData[]=u8R"///(-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDoUaLxcCvcgWzS1ukXC56F9YWx PlmuwHa9zPFR4+tinzhtG8PRSgPB7UOAzaFu4hKimPOcOrQaRUof/PhSNGxZAhad d+/kot0I8y7pwzeza9EAEwpQIki7RextKlWDRLRvaQGLjnW7SUrF2k62zJCdtow0 KcfR+Hx1+7Z4wYYFHwIDAQAB -----END PUBLIC KEY----- )///"; Botan::MemoryVector<byte> pem(pemData,sizeof(pemData)-1); std::unique_ptr<Public_Key> publicKey{ Botan::X509::load_key(pem) }; Botan::AutoSeeded_RNG rng; PK_Encryptor_EME en(*publicKey,"EME-PKCS1-v1_5"); auto ans=en.encrypt((const byte*)"12345",5,rng); std::cout<<"encode rsa is : "; for (const auto varI:ans) { std::cout<<std::hex<<int(varI); } std::cout<<std::endl; }