OK
This code works.
I built this in MS Visual Studio 2005.
Create a normal windows application project in C#, called 'dcfundrm
'.
Place your '.dcf' files in the project folder at:
dcfundrm\bin\Debug
Make sure that you add a reference for 'ChilkatDotNet2.dll' as directed at 'http://www.example-code.com/csharp/step2.asp'
Once you have built the project, using the code below, run the program (CTL + F5), and type in the name of your '.dcf' file in the text box and press the submit button.
Code assembly:
1) Create a text box and button in 'Form1.cs[design]'.
2) In 'Form1.cs' copy & paste the following:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Chilkat;
namespace dcfundrm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
createFile(textBox1.Text);
}
private void createFile(string fileName)
{
string fname = "Theme-Halloween.dcf";
if(fileName=="")
{
fname = "Theme-Halloween.dcf";
}
else
{
fname = fileName;
}
if(fname.IndexOf(".")!=-1)
{
fname = fname.Substring(0, fname.Length - 4);
}
// A Chilkat Crypt unlock code will work here.
Chilkat.OmaDrm omaDrm = new Chilkat.OmaDrm();
omaDrm.UnlockComponent("Anything for 30-day trial");
Chilkat.Crypt2 crypt = new Chilkat.Crypt2();
// Load an OMA DRM file.
omaDrm.LoadDcfFile(fname + ".dcf");
string msg = omaDrm.ContentType + "\r\n" +
omaDrm.ContentUri + "\r\n" +
omaDrm.Headers;
MessageBox.Show(msg);
// Get a specific header
MessageBox.Show("Content-Description = " + omaDrm.GetHeaderField("content-description"));
// Get the AES initialization vector
// Display the IV in hex format.
MessageBox.Show("IV: " + crypt.Encode(omaDrm.IV, "hex"));
// Display 1st 20 bytes of encrypted data in hex format
MessageBox.Show("Encrypted Data: " + crypt.Encode(omaDrm.EncryptedData, "hex").Substring(0, 20));
// To decrypt, set the Base64 key and decrypt...
omaDrm.Base64Key = "BiVVJOQee6y4PWYL+fbvJA==";
// Display 1st 20 bytes of the decrypted data in hex format
MessageBox.Show("Decrypted Data: " + crypt.Encode(omaDrm.DecryptedData, "hex").Substring(0, 20));
// Save the decrypted data to a file.
bool success = omaDrm.SaveDecrypted(fname + ".mp3");
if (!success)
{
MessageBox.Show(omaDrm.LastErrorText);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}