Share via


Key Message (keyMessage)

The format of the key message is specific to a particular content protection system. The format of the PlayReady key message is an XML-formatted Unicode string that is contained in the MediaKeyMesageEvent.message from the KeyMessage event. The PlayReady key message uses the following schema:

<PlayReadyKeyMessage type="LicenseAcquisition" >
  <LicenseAcquisition version="1.0" >
    <Challenge encoding="base64encoded">
      License challenge
    </Challenge>
    <HttpHeaders>
      <HttpHeader>
        <name>Content-Type</name>
        <value>"content type data"</value>
      </HttpHeader>
      <HttpHeader>
        <name>SOAPAction</name>
        <value>soap action</value>
      </HttpHeader>
      ....
    </HttpHeaders>
  </LicenseAcquisition>
</PlayReadyKeyMessage>
  

Once you have received the key message event from the PlayReady CDM, you should parse out the HttpHeader information from the HttpHeaders field. When sending your license acquisition challenge request to the Playready license server using an HTTPRequest, you need to set up these headers as part of the request.

The following sample demonstrates how to parse the key message:

function parseKeyMessage(strKeyMessage)
{

  var decodedChallenge;
  var headers=new Array();

  try {
    var parser = new DOMParser();
    var xmlDoc = parser.parseFromString(strKeyMessage, "application/xml");

    if ( xmlDoc.getElementsByTagName("Challenge")[0] )
    {
      var Challenge = xmlDoc.getElementsByTagName("Challenge")[0].childNodes[0].nodeValue;
      if ( Challenge )
      {
        decodedChallenge = Base64.decode( Challenge );
      }
    }
    else
    {
      console.log(“function(parseKeyMessage) can not find Challenge in keyMessage”);
    }

    var headerNameList = xmlDoc.getElementsByTagName("name");
    var headerValueList = xmlDoc.getElementsByTagName("value");

    if( headerNameList.length != headerValueList.length )
    {
      console.log(“function(parseKeyMessage)invalid header name/value pair in keyMessage”);
    }

    for ( var i=0; i < headerNameList.length; i++ )
    {
      headers[i] = {name:headerNameList[i].childNodes[0].nodeValue,
                          value:headerValueList[i].childNodes[0].nodeValue} ;
    }
  }
  catch (ex){
    console.log(“function(parseKeyMessage): exception %x “, ex);
    return;
  }

  return {LAChallenge: decodedChallenge, Headers: headers};
};