Skip to main content

Posts

Showing posts from 2014

Encryption and Decryption in .NET

You want to scramble data on the server side before it's saved and also want to retrieve it later and unscramble it. Encryption and Decryption is what you want. There are 2 types, Symmetric and Asymmetric. Symmetric uses 1 key (private) and this same key is used to encrypt and decrypt. Asymmetric uses 2 keys, 1 for encryption (public) and 1 for decryption (private) So at least a key is required in all cases. This needs to be stored somewhere. Seems that hardcoded in code or in a config file seems to be the preference. When storing the key in the web.config ensure that the section is encrypted itself so that it's not human readable  http://msdn.microsoft.com/en-us/library/zhhddkxy(v=vs.100).aspx . .NET has a bunch of classes which can be do the actual work, see the System.Security.Cryptography namespace. See the SymmetricAlgorithm and the AsymmetricAlgorithm classes. Use the (SymmetricAlgorithm)CryptoConfig.CreateFromName(provider)) and get the provider form the w...