# Import a RSA key

This sample app demonstrates how to generate a RSA key and export it given standard format.

1. Get a SecurityFactory instance

auto &secFact = telux::sec::SecurityFactory::getInstance();
    Copy to clipboard

2. Get a CryptoManager instance

std::shared_ptr<telux::sec::ICryptoManager> cryptMgr;
    
    cryptMgr = secFact.getCryptoManager(ec);
    if (!cryptMgr) {
        std::cout << "Can't allocate CryptoManager, err: " <<
                static_cast<int>(ec) << std::endl;
        return -1;
    }
    Copy to clipboard

3. Define the key data to be imported

/*
     * Generated using openssl:
     * openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:3 -out rsa_key.der -outform der
     * openssl pkcs8 -in rsa_key.der -inform der -out rsa_key_pkcs8.der -outform der -topk8 -nocrypt
     * xxd -i rsa_key_pkcs8.der
     */
    uint8_t rsaKey[] = {
            0x30, 0x82, 0x04, 0xbd, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
            0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
            0x04, 0xa7, 0x30, 0x82, 0x04, 0xa3, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01,
            0x01, 0x00, 0xba, 0xdb, 0xd3, 0x09, 0x92, 0x24, 0xd9, 0x18, 0xd7, 0x75,
            0x6c, 0xd5, 0x27, 0xef, 0xe5, 0x9c, 0xca, 0xd3, 0x81, 0xbf, 0xf0, 0xf4,
            0x0a, 0xa0, 0x3f, 0x2b, 0x54, 0x68, 0x67, 0xef, 0x34, 0xce, 0x5d, 0x3d,
            0xde, 0xa5, 0x15, 0xcb, 0xd7, 0xae, 0xa2, 0xf3, 0x57, 0xb7, 0x02, 0xca,
            0x02, 0x65, 0x85, 0x4d, 0xc7, 0xea, 0x6a, 0xbd, 0xa6, 0xd7, 0x32, 0xce,
            0xe5, 0xeb, 0xa4, 0xf9, 0xf1, 0xfb, 0x76, 0x2a, 0x9d, 0xb5, 0x99, 0x4f,
            0xb5, 0x69, 0x06, 0x88, 0xe3, 0x3a, 0xcb, 0xd0, 0x43, 0x4b, 0x11, 0xd4,
            0x74, 0xbe, 0x6f, 0xf9, 0x50, 0x04, 0xba, 0x3e, 0x08, 0xeb, 0x0c, 0xba,
            0xcd, 0x57, 0x95, 0x1e, 0x0f, 0xd7, 0x42, 0x09, 0x9a, 0x4d, 0x20, 0x86,
            0x5a, 0xcc, 0xa0, 0xaa, 0x20, 0x40, 0x72, 0xd4, 0xe8, 0x39, 0xd5, 0x75,
            0x53, 0x73, 0x8b, 0x58, 0x4d, 0xe5, 0x2f, 0xb2, 0x7a, 0xc2, 0x59, 0xce,
            0xcf, 0x69, 0x8c, 0x19, 0x35, 0x8d, 0x0f, 0x18, 0x30, 0xda, 0xc0, 0x9d,
            0x4f, 0x9e, 0xfa, 0xec, 0xca, 0x39, 0x6c, 0xac, 0x02, 0xa7, 0x6a, 0xfd,
            0xa9, 0x10, 0x53, 0xd1, 0x78, 0x96, 0x68, 0x0a, 0x0b, 0xd5, 0x13, 0xb9,
            0x09, 0xa3, 0x14, 0x85, 0xd4, 0xb1, 0x9d, 0x3d, 0x7e, 0x2d, 0xbc, 0x81,
            0x18, 0x81, 0x0c, 0x81, 0x6f, 0xf5, 0xed, 0x05, 0x25, 0x7d, 0x12, 0xd1,
            0x1b, 0xc1, 0x4b, 0x5f, 0x5d, 0x3c, 0xfd, 0x0e, 0x76, 0xf0, 0x1d, 0x95,
            0xb7, 0x41, 0xbc, 0xdb, 0x3c, 0x34, 0x04, 0x83, 0xcc, 0xff, 0x67, 0xe0,
            0x48, 0x6e, 0x40, 0xb1, 0x40, 0xd8, 0xef, 0xe6, 0xed, 0x36, 0xe7, 0xe8,
            0xf8, 0x68, 0x71, 0x25, 0xb4, 0x96, 0x05, 0x73, 0xa4, 0x8a, 0x71, 0x36,
            0xca, 0x01, 0x6c, 0xfe, 0xd0, 0xd2, 0x36, 0xac, 0x0f, 0xff, 0x29, 0x94,
            0xf3, 0xcf, 0x9a, 0x36, 0x88, 0xf9, 0x02, 0x01, 0x03, 0x02, 0x82, 0x01,
            0x00, 0x7c, 0x92, 0x8c, 0xb1, 0x0c, 0x18, 0x90, 0xbb, 0x3a, 0x4e, 0x48,
            0x8e, 0x1a, 0x9f, 0xee, 0x68, 0x87, 0x37, 0xab, 0xd5, 0x4b, 0x4d, 0x5c,
            0x6a, 0xd4, 0xc7, 0x8d, 0x9a, 0xef, 0xf4, 0xcd, 0xde, 0xe8, 0xd3, 0xe9,
            0xc3, 0x63, 0xdd, 0x3a, 0x74, 0x6c, 0xa2, 0x3a, 0x7a, 0x01, 0xdc, 0x01,
            0x99, 0x03, 0x89, 0x2f, 0xf1, 0x9c, 0x7e, 0x6f, 0x3a, 0x21, 0xdf, 0x43,
            0xf2, 0x6d, 0xfb, 0xf6, 0xa7, 0xa4, 0x1c, 0x69, 0x23, 0xbb, 0x8a, 0x78,
            0xf0, 0xaf, 0x05, 0xec, 0xd1, 0xdd, 0x35, 0x82, 0x32, 0x0b, 0xe2, 0xf8,
            0x7e, 0xf5, 0x50, 0xe0, 0x03, 0x26, 0xd4, 0x05, 0xf2, 0x08, 0x7c, 0x88,
            0xe5, 0x0e, 0x14, 0x0a, 0x8f, 0x81, 0x5b, 0xbc, 0x33, 0x6b, 0x04, 0x3c,
            0x88, 0x6b, 0x1c, 0x15, 0x80, 0x4c, 0x8d, 0xf0, 0x26, 0x8e, 0x4e, 0x37,
            0xa2, 0x5c, 0xe5, 0x89, 0x43, 0x75, 0x21, 0xa7, 0x2b, 0x17, 0x8c, 0xa2,
            0xfa, 0xb2, 0x7c, 0x0c, 0x74, 0x96, 0x44, 0x1c, 0x96, 0x3e, 0xd7, 0xd7,
            0x94, 0xc1, 0x31, 0x3b, 0x96, 0x57, 0x7b, 0xc6, 0xdc, 0xac, 0x2c, 0x4c,
            0x5a, 0xbc, 0xa7, 0x91, 0x63, 0x8f, 0x40, 0x3b, 0x0d, 0x7b, 0xb9, 0xc9,
            0x56, 0xd5, 0x19, 0x81, 0xb2, 0x3f, 0x1e, 0xe4, 0xca, 0xdd, 0x91, 0x63,
            0xfd, 0xf5, 0xbe, 0x43, 0x64, 0xa0, 0x1a, 0xbf, 0xa1, 0x52, 0x75, 0x81,
            0x16, 0x58, 0x71, 0x7e, 0x9b, 0x10, 0x29, 0x2f, 0x4e, 0xc9, 0x13, 0x2f,
            0xe6, 0x76, 0xdf, 0x86, 0x2a, 0xd6, 0x29, 0x33, 0x88, 0x83, 0x16, 0x2d,
            0xd0, 0xf1, 0xf7, 0x37, 0xd7, 0x0d, 0x99, 0x40, 0x0b, 0x15, 0xbc, 0xe4,
            0x84, 0x01, 0xbf, 0x21, 0xd2, 0xc5, 0x06, 0x62, 0xc4, 0xce, 0x88, 0xfa,
            0xec, 0x23, 0xc9, 0x28, 0x75, 0x7d, 0x0b, 0xbc, 0xef, 0x3d, 0x83, 0x77,
            0x06, 0x43, 0x30, 0x10, 0xab, 0x02, 0x81, 0x81, 0x00, 0xea, 0x72, 0x60,
            0xa3, 0xfc, 0xff, 0x54, 0x7f, 0xc5, 0x67, 0x81, 0x00, 0xd4, 0x02, 0x91,
            0x9b, 0xa3, 0x18, 0x22, 0x57, 0xfe, 0x92, 0xe5, 0x76, 0xfc, 0xc0, 0xbe,
            0xb6, 0xa2, 0x88, 0xad, 0x07, 0x5d, 0xf9, 0xce, 0x1f, 0x37, 0xbe, 0xac,
            0x91, 0xf2, 0x88, 0xf6, 0xe1, 0xec, 0x94, 0x93, 0x10, 0x9e, 0x4b, 0x38,
            0xa7, 0x19, 0x43, 0x69, 0x55, 0x41, 0x2e, 0x18, 0x52, 0x4a, 0x3d, 0xd8,
            0x08, 0xbb, 0xb0, 0x61, 0x3d, 0x61, 0xd5, 0xb2, 0x30, 0x25, 0x11, 0xb1,
            0xd7, 0xe6, 0x3e, 0x9c, 0x15, 0x0e, 0xf0, 0x85, 0x10, 0xd9, 0x81, 0x9e,
            0x3f, 0x36, 0xc4, 0xcf, 0x5c, 0xf1, 0xf3, 0x63, 0xb5, 0x14, 0x6e, 0xc8,
            0x9c, 0x53, 0x88, 0xff, 0x87, 0x91, 0x43, 0x0e, 0x94, 0x75, 0xe7, 0xae,
            0x0a, 0xc8, 0x43, 0x19, 0x89, 0xcc, 0xc1, 0xc0, 0xc4, 0x92, 0xb6, 0x11,
            0xfe, 0xb6, 0xa4, 0xf8, 0x61, 0x02, 0x81, 0x81, 0x00, 0xcc, 0x09, 0x7a,
            0x4d, 0x83, 0x5f, 0xce, 0x5e, 0x68, 0x4a, 0x84, 0xf8, 0x8e, 0x56, 0xfa,
            0xa4, 0x36, 0x0a, 0xce, 0x7f, 0xea, 0xdf, 0x72, 0xe5, 0x6b, 0xfa, 0x77,
            0xd1, 0x96, 0x4d, 0x71, 0x79, 0xb3, 0x2f, 0xe5, 0x21, 0xa2, 0x63, 0xaf,
            0x0e, 0xe2, 0x56, 0x9b, 0x44, 0x51, 0xfa, 0x93, 0xec, 0xd1, 0xdb, 0xc9,
            0xdd, 0x02, 0xa0, 0xa1, 0x89, 0xbb, 0xae, 0xed, 0xb8, 0xcc, 0xe3, 0x02,
            0x17, 0x0b, 0x04, 0xbe, 0x17, 0x02, 0xfa, 0xfd, 0xc9, 0xca, 0xe7, 0x3d,
            0x90, 0x24, 0x4d, 0x56, 0xde, 0xb4, 0x55, 0x7a, 0xa1, 0xc9, 0xbd, 0x65,
            0x75, 0x9e, 0xf9, 0x9d, 0xb9, 0x69, 0x8d, 0xa9, 0x71, 0x32, 0xde, 0xd9,
            0x06, 0x1a, 0xfe, 0x02, 0x52, 0x4c, 0xa7, 0x01, 0xce, 0xc5, 0x81, 0xa3,
            0x94, 0x6f, 0x0d, 0xfa, 0x98, 0x2e, 0x58, 0xb3, 0xd3, 0xba, 0x99, 0xaf,
            0x47, 0x7e, 0xc9, 0x77, 0x99, 0x02, 0x81, 0x81, 0x00, 0x9c, 0x4c, 0x40,
            0x6d, 0x53, 0x54, 0xe2, 0xff, 0xd8, 0xef, 0xab, 0x55, 0xe2, 0xac, 0x61,
            0x12, 0x6c, 0xba, 0xc1, 0x8f, 0xff, 0x0c, 0x98, 0xf9, 0xfd, 0xd5, 0xd4,
            0x79, 0xc1, 0xb0, 0x73, 0x5a, 0x3e, 0xa6, 0x89, 0x6a, 0x25, 0x29, 0xc8,
            0x61, 0x4c, 0x5b, 0x4f, 0x41, 0x48, 0x63, 0x0c, 0xb5, 0xbe, 0xdc, 0xd0,
            0x6f, 0x66, 0x2c, 0xf0, 0xe3, 0x80, 0xc9, 0x65, 0x8c, 0x31, 0x7e, 0x90,
            0x05, 0xd2, 0x75, 0x96, 0x28, 0xeb, 0xe3, 0xcc, 0x20, 0x18, 0xb6, 0x76,
            0x8f, 0xee, 0xd4, 0x68, 0x0e, 0x09, 0xf5, 0xae, 0x0b, 0x3b, 0xab, 0xbe,
            0xd4, 0xcf, 0x2d, 0xdf, 0x93, 0x4b, 0xf7, 0x97, 0xce, 0x0d, 0x9f, 0x30,
            0x68, 0x37, 0xb0, 0xaa, 0x5a, 0x60, 0xd7, 0x5f, 0x0d, 0xa3, 0xef, 0xc9,
            0x5c, 0x85, 0x82, 0x11, 0x06, 0x88, 0x81, 0x2b, 0x2d, 0xb7, 0x24, 0x0b,
            0xff, 0x24, 0x6d, 0xfa, 0xeb, 0x02, 0x81, 0x81, 0x00, 0x88, 0x06, 0x51,
            0x89, 0x02, 0x3f, 0xde, 0xe9, 0x9a, 0xdc, 0x58, 0xa5, 0xb4, 0x39, 0xfc,
            0x6d, 0x79, 0x5c, 0x89, 0xaa, 0x9c, 0x94, 0xf7, 0x43, 0x9d, 0x51, 0xa5,
            0x36, 0x64, 0x33, 0xa0, 0xfb, 0xcc, 0xca, 0x98, 0xc1, 0x16, 0xed, 0x1f,
            0x5f, 0x41, 0x8f, 0x12, 0x2d, 0x8b, 0xfc, 0x62, 0x9d, 0xe1, 0x3d, 0x31,
            0x3e, 0x01, 0xc0, 0x6b, 0xb1, 0x27, 0xc9, 0xf3, 0xd0, 0x88, 0x97, 0x56,
            0xba, 0x07, 0x58, 0x7e, 0xba, 0x01, 0xfc, 0xa9, 0x31, 0x31, 0xef, 0x7e,
            0x60, 0x18, 0x33, 0x8f, 0x3f, 0x22, 0xe3, 0xa7, 0x16, 0x86, 0x7e, 0x43,
            0xa3, 0xbf, 0x51, 0x13, 0xd0, 0xf1, 0x09, 0x1b, 0xa0, 0xcc, 0x94, 0x90,
            0xae, 0xbc, 0xa9, 0x56, 0xe1, 0x88, 0x6f, 0x56, 0x89, 0xd9, 0x01, 0x17,
            0xb8, 0x4a, 0x09, 0x51, 0xba, 0xc9, 0x90, 0x77, 0xe2, 0x7c, 0x66, 0x74,
            0xda, 0x54, 0x86, 0x4f, 0xbb, 0x02, 0x81, 0x81, 0x00, 0xbd, 0x98, 0x4a,
            0xd6, 0xee, 0xb6, 0xe6, 0xab, 0x14, 0x80, 0x17, 0x4c, 0x59, 0x67, 0xc4,
            0x62, 0x2d, 0x77, 0x89, 0x83, 0x31, 0x49, 0x5e, 0x5a, 0x45, 0x3a, 0x05,
            0x93, 0x46, 0x30, 0x4c, 0x82, 0xcd, 0xe7, 0xcc, 0xbe, 0x12, 0x54, 0x34,
            0x54, 0xe0, 0x47, 0x9a, 0x9b, 0x68, 0x12, 0x4e, 0x7b, 0x2d, 0xf2, 0x73,
            0x61, 0x17, 0x4a, 0x69, 0x6c, 0xfc, 0x34, 0xdf, 0x63, 0x25, 0xf0, 0x33,
            0x27, 0x20, 0x8b, 0xcd, 0x51, 0x49, 0xe7, 0x12, 0xff, 0x31, 0x64, 0x8b,
            0xe6, 0x67, 0x9e, 0x5a, 0xd6, 0x0e, 0xfd, 0x29, 0xee, 0xf6, 0x6e, 0xca,
            0x04, 0xfa, 0xd4, 0x07, 0x55, 0xbd, 0xc5, 0xdf, 0xeb, 0x50, 0xad, 0x98,
            0x2a, 0x5c, 0x1a, 0x9c, 0x74, 0x4c, 0x8c, 0xfe, 0x04, 0xbe, 0x57, 0x67,
            0xb1, 0xc4, 0xa7, 0xe9, 0xd5, 0xbe, 0x31, 0xbf, 0xf4, 0x3b, 0xbf, 0x7c,
            0x7b, 0x32, 0x8c, 0x48, 0x23 };
    
    std::vector<uint8_t> keyData(rsaKey, rsaKey + (sizeof(rsaKey)/sizeof(rsaKey[0])));
    Copy to clipboard

4. Define parameters using CryptoParamBuilder for the key

std::shared_ptr<telux::sec::ICryptoParam> cp;
    
    cp = telux::sec::CryptoParamBuilder()
            .setAlgorithm(telux::sec::Algorithm::ALGORITHM_RSA)
            .setCryptoOperation(telux::sec::CryptoOperation::CRYPTO_OP_SIGN |
                        telux::sec::CryptoOperation::CRYPTO_OP_VERIFY)
            .setDigest(telux::sec::Digest::DIGEST_SHA_2_256 |
                    telux::sec::Digest::DIGEST_SHA_2_512)
            .setPadding(telux::sec::Padding::PADDING_RSA_PSS |
                    telux::sec::Padding::PADDING_RSA_PKCS1_1_5_SIGN)
            .build();
    Copy to clipboard

5. Import key by specifying format using importKey() API

telux::common::ErrorCode ec;
    std::vector<uint8_t> kb;
    
    ec = cryptMgr->importKey(cp, telux::sec::KeyFormat::KEY_FORMAT_PKCS8, keyData, kb);
    if (ec != telux::common::ErrorCode::SUCCESS) {
        std::cout << "Can't import key, err: " <<
                static_cast<int>(ec) << std::endl;
        return -1;
    }
    Copy to clipboard

Last Published: May 20, 2026

[Previous Topic
Export a RSA key](https://docs.qualcomm.com/bundle/publicresource/80-PF458-7/topics/RSAExportKeyApp.md) [Next Topic
Crypto accelerator](https://docs.qualcomm.com/bundle/publicresource/80-PF458-7/topics/crypto_accelerator.md)