EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Problem with XML encryption

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#1374
Posted: 10/08/2006 09:41:57
by Christian Schwarz (Standard support level)
Joined: 07/20/2006
Posts: 14

I'm trying to figure out how to encrypt an XML document using a fixed symmetric key. Altough I've used the SimpleEncryptor example (which works well) as base I'm not able to produce a working solution.

Here's a source code snippet:

using System.IO;
using SBXMLCore;
using SBXMLEnc;
using SBXMLSec;
using Unit=SBXMLDefs.Unit;

namespace XmlEnc
{
class MainClass
{
private static readonly byte[] SymmetricKeyData = new byte[]
{
0x00, 0x00, 0x00, 0x10, 0x00, 0x4b, 0xe4, 0x70, 0xb1, 0x0d, 0x96, 0xd8, 0x72, 0xa6, 0x7d, 0xab,
0x93, 0x88, 0x27, 0x89, 0x00, 0x00, 0xaf, 0xb2, 0x26, 0x5b, 0xcc, 0xb3, 0x16, 0x00, 0x3e, 0xde,
0x1e, 0xf4, 0x36, 0x1e, 0xc2, 0x07, 0xc2, 0x0b, 0x45, 0x3e, 0x44, 0xb6, 0x32, 0x40, 0x30, 0x10,
0xaa, 0x40, 0x23, 0x68, 0x37, 0x10
};

static void Main(string[] args)
{
TElXMLKeyInfoSymmetricData keyInfoSymmetricData = new TElXMLKeyInfoSymmetricData(true);
int size = SymmetricKeyData.Length;
keyInfoSymmetricData.Key.Load(SymmetricKeyData, 0, ref size);
keyInfoSymmetricData.Key.GenerateIV(128);

using (TElXMLEncryptor xmlEncryptor = new TElXMLEncryptor())
{
xmlEncryptor.EncryptKey = false;
xmlEncryptor.EncryptedDataType = SBXMLSec.Unit.xedtElement;
xmlEncryptor.EncryptionMethod = SBXMLSec.Unit.xemAES;
xmlEncryptor.KeyName = "";
xmlEncryptor.KeyData = keyInfoSymmetricData;

TElXMLDOMDocument xmlDocumentEnc = new TElXMLDOMDocument();

using (FileStream fsInput = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.None))
{
xmlDocumentEnc.LoadFromStream(fsInput);
}

TElXMLDOMNode xmlNode = xmlDocumentEnc.DocumentElement;
xmlEncryptor.Encrypt(xmlNode);

TElXMLDOMNode xmlNodeEnc = xmlEncryptor.Save(xmlDocumentEnc);
xmlNode.ParentNode.ReplaceChild(xmlNodeEnc, xmlNode);

using (FileStream fsOutput = new FileStream(args[1], FileMode.Create, FileAccess.Write, FileShare.None))
{
xmlDocumentEnc.SaveToStream(fsOutput, Unit.xcmNone, "");
}
}

}
}
}

All works well until saving the encrypted node. At this point a SBXMLDefs.EXMLEncError exception with message "EncryptedData not loaded" is thrown.

What's wrong with my code?

Greetings, Christian
#1375
Posted: 10/08/2006 09:45:37
by Eugene Mayevski (EldoS Corp.)

I don't see a call to SetLicenseKey in your code. Did you miss or omit it?


Sincerely yours
Eugene Mayevski
#1376
Posted: 10/08/2006 09:56:10
by Christian Schwarz (Standard support level)
Joined: 07/20/2006
Posts: 14

I feel so stupid... That was the problem!

Many thanks for your fast response!

Reply

Statistics

Topic viewed 2599 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!