boost::corosio::tls_context::set_password_callback

Set the password callback for encrypted keys.

Synopsis

template<typename Callback>
void
set_password_callback(Callback callback);

Description

Installs a callback that provides passwords for encrypted private keys and PKCS#12 files. The callback is invoked when loading encrypted key material.

Example

ctx.set_password_callback(
    []( std::size_t max_len, tls_password_purpose purpose )
    {
        // In practice, prompt user or read from secure storage
        return std::string( "my-key-password" );
    });

// Now load encrypted key
ctx.use_private_key_file( "encrypted.key", tls_file_format::pem );

Template Parameters

Name Description

Callback

A callable with signature std::string( std::size_t max_length, password_purpose purpose ).

Parameters

Name Description

callback

The password callback. It receives the maximum password length and the purpose (reading or writing), and returns the password string.

See Also

tls_password_purpose

Created with MrDocs