views:

221

answers:

2

Hi all,

I am looking to obfuscate a data access layer which is written using NHibernate. The problem is, the mappings are done in XML files which are embedded as resources in the class library - which means the mapping are in clear text.

Two potential solutions are to use: 1. Nhibernate Mapping attributes (NHMA) to decorat ethe entities mapped (so, when the obfuscated code runs, NHibernate will map it to the obfuscated class names) 2. Fluent NHibernate (again, the mapping is in code, so obfuscation should not be a problem - I think).

Now, both these solutions will not work if we use HQL to do the queries - since the queries would refer to the original class and field/property names!

Is there a solution for this? Can we have class/property names aliased in NHMA/Fluent mappings?

Will the Criteria API help somehow if we convert the HQL queries to use the NHibernate Criteria API?

(I do know the benefits and disadvantages/futility of obfuscation and the purpose it is useful for - so this question is not meant to discuss that at all. In other words, please dont worry about discussing 'why' I want to do this!)

Thanks,

Krishna.

+1  A: 

The only solution I can think of is to use Linq to NHibernate. Currently it is part of the NHibernate Contrib Project and not completely stable. It will be part of the NHibernate 2.1 release which currently has "Alpha" status and should be stable fairly soon.

For the mappings I would use Fluent NHibernate. And since both Linq and Fluent NHibernate use Lambda expressions it should work with obfuscation.

Albic
A: 

NHibernate Configuration object is pretty flexible. By calling:

var lConfig = new Configuration();
lConfig.AddXmlString("whatever xml with config");

you can add strings from whatever source. That means that your xmls can be encrypted in the assembly and decrypted when configuring NH.

But if you're just after obfuscation I think Fluent NH is your tool of choice.

Rashack