使基于 Nhibernate 的 DAL 混淆变得友好
我正在寻找混淆使用 NHibernate 编写的数据访问层。 问题是,映射是在 XML 文件中完成的,这些文件作为资源嵌入到类库中 - 这意味着映射是明文形式的。
可以使用两种可能的解决方案: 1. Nhibernate映射属性(NHMA)来装饰映射的实体(因此,当混淆的代码运行时,NHibernate会将其映射到混淆的类名) 2. 流畅的NHibernate(同样,映射是在代码中,所以混淆应该不是问题 - 我认为)。
现在,如果我们使用 HQL 进行查询,这两种解决方案都将不起作用 - 因为查询将引用原始类和字段/属性名称!
有解决办法吗? 我们可以在 NHMA/Fluent 映射中使用类/属性名称别名吗?
如果我们将 HQL 查询转换为使用 NHibernate Criteria API,Criteria API 是否会有所帮助?
(我确实知道混淆的优点和缺点/徒劳以及它的有用目的 - 所以这个问题根本不是为了讨论这个问题。换句话说,请不要担心讨论“为什么”我想这样做! )
谢谢,
克里希纳。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的唯一解决方案是使用 Linq to NHibernate。 目前它是 NHibernate Contrib 项目的一部分,并不完全稳定。 它将成为 NHibernate 2.1 版本的一部分,该版本目前处于“Alpha”状态,并且很快就会相当稳定。
对于映射,我将使用 Fluent NHibernate。 由于 Linq 和 Fluent NHibernate 都使用 Lambda 表达式,因此它应该可以与混淆一起使用。
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.
NHibernate
Configuration
对象非常灵活。 通过调用:您可以添加来自任何来源的字符串。 这意味着您的 xml 可以在程序集中加密,并在配置 NH 时解密。
但如果您只是想进行混淆,我认为 Fluent NH 是您的首选工具。
NHibernate
Configuration
object is pretty flexible. By calling: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.