Home >
In my previous article I talked about setting up an installation of Microsoft DRM, and some of the pitfalls encountered with the base set up. In this article I will detail how I refined that process.
As I described previously, with the old work flow of encoding and DRMing, there was a lot of file copying across the network. This was because the DRM code that comes with the base install of the DRM servers needs to be run on the DRM server.
For my ideal solution I would want transcoding and DRMing to be done, not only on the same machine, but in the same process. To do this I would need to gather all of the data necessary to create a DRM envelope, but in a format that can be transported easily.
Luckily in between setting up the DRM server and beginning this refinement process, I had completed a project where we DRMed all of our live audio streams. To do that I had to generate a DRM profile that encapsulated all of the necessary data into a single file. It turns out that Windows Media Encoder can use this same profile data to DRM files programmatically, and anywhere.
To generate the DRM profile I had to write the following code. Since most source code you'll run in to on this subject seems to be in C#, I'll buck the trend and show source code in VB.Net.
The below example is a VB.Net console application that uses the Windows Media Encoder library as well as the Windows Media Rights Management library.
Imports WMEncoderLib
Imports WMRMOBJSLib
Imports System.IO
Imports System.Xml
Public Class Generate
Shared Sub Main()
Dim profValue
CreateProfile()
End Sub
Shared Sub CreateProfile()
' Create a WMEncoder object.
Dim Encoder As WMEncoder
Encoder = New WMEncoder
' Create an IWMDRMContentAuthor object.
Dim DRM As IWMDRMContentAuthor
DRM = Encoder.EncoderDRMContentAuthor
' Retrieve the collection of DRM profiles.
Dim DRMProColl As IWMDRMProfileCollection
Dim KeyObj = New WMRMKeys
DRMProColl = DRM.DRMProfileCollection
' Declare variables. Specify the provider's Web site, and certificate and
' signing values. The other variables are returned.
Dim sPublicKey As String
Dim sWebURL As String
Dim vProfileID As Object
Dim vSeed As Object
Dim sPrivateKey As String
Dim sSignedPublicKey As String
Dim sSigLSCert As String
Dim sSigRootCert As String
Dim sProfilePublicKey As String
Dim sContentID As String
sContentID = KeyObj.GenerateKeyID()
KeyObj.GenerateSigningKeysEx(sPrivateKey, sPublicKey, sSignedPublicKey)
sWebURL = "http://license3.musicchoice.com/XXXX.asp"
sSigLSCert = KeyObj.GetCertificate("LSLicenseSigningCert")
sSigRootCert = KeyObj.GetCertificate("LSRootCert")
' Create the DRM profile. The public key, DRM profile ID, and
' license key seed are returned.
sProfilePublicKey = DRM.CreateDRMProfile(sWebURL, sPrivateKey, sSignedPublicKey, sSigLSCert, sSigRootCert, vProfileID, vSeed)
' Create an IWMDRMProfile object and retrieve a profile.
Dim DRMPro As IWMDRMProfile
DRMPro = DRM.GetDRMProfile(vProfileID)
' Set the rest of the properties for the DRM profile.
DRMPro.Description = "DRM for MC portable content"
DRMPro.LicenseAcquisitionURL = "http://license3.musicchoice.com/XXXX.asp"
DRMPro.Name = "MC Portable DRM"
DRMPro.V1LicenseAcquisitionURL = "http://go.microsoft.com/fwlink/?LinkId=10141"
' Add the required individualization version as an attribute.
Dim ProAttr As IWMDRMAttributes
ProAttr = DRMPro.Attributes
ProAttr.Add("SECURITYVERSION", "2.2")
ProAttr.Add("ContentID", sContentID)
Dim sDetails As String
Dim oXMLWriter As New XmlTextWriter("C:\Inetpub\wwwroot\wm\IssuedDetails.xml", System.Text.Encoding.UTF8)
oXMLWriter.WriteStartElement("Details")
oXMLWriter.WriteStartElement("Detail")
oXMLWriter.WriteAttributeString("ContentID", sContentID)
oXMLWriter.WriteAttributeString("Seed", vSeed)
oXMLWriter.WriteAttributeString("Key", sProfilePublicKey)
oXMLWriter.WriteAttributeString("PrivateKey", sPrivateKey)
oXMLWriter.WriteEndElement()
oXMLWriter.WriteEndElement()
oXMLWriter.Close()
DRMPro.Update()
DRM.ExportDRMProfile(DRMPro.ID, "password", "C:\Inetpub\wwwroot\wm\ExportProfile.drm")
End Sub
Shared Sub SaveInfo(ByVal nSeed As String, ByVal nPath As String)
Dim objStreamWriter As StreamWriter
objStreamWriter = New StreamWriter(nPath)
objStreamWriter.WriteLine(nSeed)
objStreamWriter.Close()
End Sub
End Class
In my next article I will show how to make the Window Media Encoder object use the profile we create with the application above to both encode and DRM raw files in a single process, that can be run anywhere.




Facebook Application Development
DRM is not popular jet but may be in the future?
To be more popular it should offers MORE than only to prohibilt access or identify the end user. What does mean MORE? Let's see at YouTube typing Mydrmspace. Regards.