Share via


CSecureChannelClient::SetCertificate

banner art

The SetCertificate method specifies the certificate and private key of the secure authenticated channel (SAC) client.

Syntax

HRESULT SetCertificate(
  DWORD  dwFlags,
  BYTE*  pbAppCert,
  DWORD  dwCertLen,
  BYTE*  pbAppPVK,
  DWORD  dwPVKLen
);

Parameters

  dwFlags

[in]  Specifies the type of certificate being passed to this method. It must be set to SAC_CERT_V1.

  pbAppCert

[in]  Pointer to the first byte of the certificate of the SAC client.

  dwCertLen

[in]  DWORD specifying the length of the certificate to which pbAppCert points.

  pbAppPVK

[in]  Pointer to the first byte of the private key of the SAC client.

  dwPVKLen

[in]  DWORD specifying the length of the private key to which pbAppPVK points.

Return Values

The method returns an HRESULT. All the interface methods in Windows Media Device Manager and service provider can return any of the following classes of error codes:

  • Standard COM error codes
  • Windows error codes converted to HRESULT values
  • Windows Media Device Manager error codes

For a complete list of possible error codes, see Error Codes.

Possible values include, but are not limited to, those in the following table.

Return code Description
S_OK The method succeeded.
E_INVALIDARG A parameter is invalid or is a NULL pointer.
E_FAIL An unspecified error occurred.

Remarks

Call the SetCertificate method immediately after creating the CsecureChannelClient object, as in the following Example Code.

If pbAppCert and/or pbAppPVK are NULL (or both zero) a default certificate and private key pair is used which will allow for basic functionality.

The globals pbAppCert and pbAppPVK are found in the Key.cpp file.

Example Code

// Create the client authentication object.
HRESULT hr;
m_pSAC = new CSecureChannelClient;
ExitOnNull( m_pSAC );

// Select the cert and the associated private key into the SAC.
// The cert, abCert, and private key, abPVK, are defined in the 
// supplied key.cpp file.
hr = m_pSAC->SetCertificate( SAC_CERT_V1,
                             (BYTE *)abCert, 
                             sizeof(abCert),
                             (BYTE *)abPVK, 
                             sizeof(abPVK) );
ExitOnFail( hr );

Requirements

Header: Include scclient.h.

Library: mssachlp.lib

See Also