Geeks With Blogs
Tex-blog Mobile and other stuff
Im my post: .NET Symmetric encryption sample wrapper (Ch12), I have presented a simple wrapper for encrypting data in .NET 2.0 framework. The code was for full version of library, but it can be quite easily rewritten to work also on CF - Compact Framework to be used on mobile devices. One of the missing classes no present in CF is Rfc2898DeriveBytes, you can use Smart Device Framework from OpenNETCF to substitute it as follows:

using OpenNETCF.Security.Cryptography;

// Returns salt from password.
private static byte[] Password2Salt(String password)
  int saltLength = password.Length * ((int)password[0] % 3 + 2);
  saltLength = Math.Max(8, saltLength);
  byte[] resSalt = new byte[saltLength];
  for (int i = 0; i < saltLength; ++i)
    resSalt[i] =
      Convert.ToByte(password[i % password.Length] ^ (i + 17));
  return resSalt;

// Returns symmetric algorithm with key, IV and salt extracted from
//  password string.

private static SymmetricAlgorithm GetAlgorithm(string password)
  // Init key
  byte[] saltBytes = Password2Salt(password);

  // Non CF version.
  //Rfc2898DeriveBytes rfc2898 =
  // new Rfc2898DeriveBytes(password, saltBytes);

  PasswordDeriveBytes passBytes = new PasswordDeriveBytes(password,  saltBytes,  "MD5", 1);

  // Init algorithm
  SymmetricAlgorithm sa = new RijndaelManaged();
  sa.KeySize = 128;
  byte[] key = passBytes.GetBytes(sa.KeySize / 8);
  sa.Key = key;
  sa.IV = passBytes.GetBytes(sa.BlockSize / 8);
return sa;

Posted on Thursday, February 7, 2008 3:35 AM | Back to top

Comments on this post: Fix: Symmetric encryption wrapper for .NET 2.0 Compact Framework

# re: Fix: Symmetric encryption wrapper for .NET 2.0 Compact Framework
Requesting Gravatar...
From cfAes, there seems to be a way to use Rfc2898DeriveBytes with OpenNETCF.
But I couldn't figure out how to achieve that.
Could you have a look and post your workarounds plz?
Left by Kelvin on Feb 07, 2010 9:31 PM

Your comment:
 (will show your gravatar)

Copyright © Martinez | Powered by: