Using the RSA sample from the ebook (on a mini). It keeps throwing Decrypt exception. Any thoughts? I ran out of ideas.
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### Microsoft.SPOT.Cryptography.Key_RSA::Decrypt [IP: 0000] ####
#### FEZ_Mini_Application1.Program::TestRSA [IP: 0091] ####
#### FEZ_Mini_Application1.Program::Main [IP: 0012] ####
public static void TestRSA()
{
//this is shared between public and private keys
byte[] module = new byte[] {0x31, 0xa1, 0xef, 0xdf, 0x59, 0x8a, 0x69, 0x4a, 0x14, 0x05, 0x6a, 0x00, 0x0e, 0x62, 0x89, 0xf7, 0xb4, 0x14, 0x98, 0x3c, 0x9b, 0xe8, 0xf9, 0xd2, 0xa7, 0xe1, 0x7d, 0x30, 0x32, 0x03, 0x57, 0x0c, 0x50, 0xd9, 0xa3, 0x03, 0x21, 0x2a, 0xfd, 0x92, 0x59, 0x4b, 0xdc, 0x04, 0x8d, 0xc1, 0xaf, 0x0a, 0x6f, 0x47, 0x1f, 0xb7, 0xa6, 0xea, 0x20, 0xcc, 0x65, 0x06, 0xd6, 0xe8, 0x26, 0x54, 0x24, 0xea, 0x6b, 0x89, 0x49, 0xf0, 0x39, 0x07, 0xce, 0x3c, 0x27, 0xfb, 0xe2, 0x95, 0x35, 0x8d, 0x41, 0x00, 0x3f, 0x12, 0xb0, 0xda, 0xd9, 0x80, 0x13, 0x7d, 0xd2, 0xc2, 0xed, 0x2e, 0xba, 0xeb, 0x5d, 0xe2, 0x42, 0x58, 0x8e, 0xc6, 0xf8, 0x83, 0x4d, 0x93, 0xfa, 0x79, 0x46, 0x35, 0x71, 0x9a, 0x41, 0xd5, 0x60, 0x22, 0x04, 0xfa, 0x6d, 0x7a, 0x39, 0x0a, 0x42, 0x71, 0x6d, 0xb3, 0x7d, 0x1a, 0xcc, 0x94,
};
//the private key...for dycrypting
byte[] private_key = new byte[] {0x01, 0x30, 0x7e, 0x9b, 0x8d, 0x6a, 0x9d, 0xe9, 0xc4, 0xe5, 0xc7, 0x71, 0x6f, 0x6f, 0xe7, 0xc2, 0xbf, 0xf8, 0x58, 0x72, 0x7f, 0x21, 0xf2, 0x6d, 0x19, 0xc2, 0x83, 0x17, 0xf8, 0xa9, 0xb9, 0x51, 0x10, 0x16, 0xfc, 0x06, 0x7d, 0xb1, 0x36, 0x6a, 0xaf, 0x43, 0x7d, 0xa3, 0x86, 0x7c, 0xf4, 0x45, 0xa7, 0x3e, 0x8b, 0x4b, 0x7c, 0x9b, 0x89, 0x48, 0x46, 0x6c, 0xf5, 0x85, 0x79, 0x15, 0x6d, 0x55, 0xcf, 0x8f, 0x43, 0x39, 0xde, 0xe8, 0xd4, 0x3a, 0xcb, 0xca, 0x86, 0x49, 0x6a, 0x44, 0x62, 0xdc, 0x77, 0x00, 0x88, 0xfa, 0x5a, 0x71, 0x12, 0xde, 0x1b, 0x48, 0xfa, 0x70, 0xc4, 0x95, 0x1d, 0xe0, 0x4c, 0xb2, 0x96, 0x19, 0x89, 0x43, 0xd4, 0x6f, 0x2c, 0x0d, 0x05, 0x8c, 0x7f, 0xb4, 0x30, 0x5b, 0xd6, 0x9e, 0x2f, 0xd8, 0xa2, 0xb9, 0x22, 0x03, 0xc0, 0x26, 0xdf, 0x2b, 0xb3, 0x95, 0x77, 0x4d,
};
Debug.Print("Module: " +module.Length);
Debug.Print("Private: " + private_key.Length);
// the public key, always starts with 0x01, 0x00, 0x01,...
// and the reast are all zeros
byte[] public_key = new byte[128];
public_key[0] = 1;
public_key[2] = 1;
Key_RSA rsa_encrypt = new Key_RSA(module, public_key);
Key_RSA rsa_decrypt = new Key_RSA(module, private_key);
// The data we want to encrypt
string original_string = "FEZ is so easy";
//convert to byte array
byte[] original_data = UTF8Encoding.UTF8.GetBytes(original_string);
//Encrypt the data
byte[] encrypted_bytes = rsa_encrypt.Encrypt(original_data, 0, original_data.Length, null);
//Decrypt the data
byte[] decrypted_bytes = rsa_decrypt.Decrypt( encrypted_bytes, 0, encrypted_bytes.Length, null);
//print the decrypted data
string decrypted_string = new string(Encoding.UTF8.GetChars(decrypted_bytes));
Debug.Print("Data Size= " + original_string.Length + " Data= " + original_string);
Debug.Print("Encrypted Data size= " + encrypted_bytes.Length + " Decrypted Data= " + decrypted_string);
}