alistairphillips.com

I’m : a web and mobile developer based in the Australia.


OpenNETCF Encryption

Got encryption working in .NETCF thanks to the help of the OpenNETCF guys. This post is really meant for my own reference so that I can list the sites that had the info I needed:

In the end all of that adds up to this:

    byte[] encryptedData;
    byte[] decryptedData;
    byte[] dataBytes = System.Text.ASCIIEncoding.ASCII.GetBytes("hello");

    //Encrypt
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    encryptedData = rsa.EncryptValue(dataBytes);

    //Decrypt
    decryptedData = rsa.DecryptValue(encryptedData);
    MessageBox.Show("Encrypted Data : " + System.Text.ASCIIEncoding.ASCII.GetString(encryptedData, 0, encryptedData.Length));
    MessageBox.Show("Decrypted Data : " + System.Text.ASCIIEncoding.ASCII.GetString(decryptedData, 0, decryptedData.Length));

which encrypts the string "Hello" and then decrypts it again!