O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an encrypted string type

In this age of identity theft, data security is more important than ever. Sensitive data such as credit card numbers should always be encrypted. In this recipe, I'll show you how to use NHibernate to encrypt a single property.

How to do it...

  1. Create a new class library project named EncryptedStringExample.
  2. Add references to NHibernate.dll, log4net.dll, and NHibernate.Castle.ByteCode.dll.
  3. Add a new public interface named IEncryptor with the following three method definitions:
    public interface IEncryptor
    {
      string Encrypt(string plainText);
      string Decrypt(string encryptedText);
      string EncryptionKey { get; set; }
    }
  4. Create an implementation of IEncryptor named SymmetricEncryptorBase using the following code:
    public abstract ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required