Using scrypt in SL 4

Oct 19, 2011 at 5:28 PM


It seems i'm unable to understand how i will be using the Public and Private key. My code is as below:

private void generateKey_Click(object sender, RoutedEventArgs e)
            RSACrypto r = new RSACrypto(1024);
            r.OnKeysGenerated += keygenerated;

        private void keygenerated(object g)
            RSACrypto rsa = (RSACrypto)g;

            textBox1.Text = rsa.ToXmlString(true);

        public void Encrypt_Click(object sender, RoutedEventArgs e)
            RSACrypto r = new RSACrypto(1024);
            byte[] rawBytes = System.Text.Encoding.UTF8.GetBytes(textBox2.Text);
            byte[] encBytes = r.EncryptPrivate(rawBytes);
            bb = encBytes;
            String text = System.Convert.ToBase64String(encBytes, 0, encBytes.Length);

            textBox5.Text = text;

        private void decrypt_Click(object sender, RoutedEventArgs e)
            RSACrypto r = new RSACrypto(1024);
            RSAParameters para = new RSAParameters();
            para.N = System.Text.Encoding.UTF8.GetBytes(textBox6.Text);
            para.E = System.Text.Encoding.UTF8.GetBytes(textBox7.Text);
            para.P = System.Text.Encoding.UTF8.GetBytes(textBox8.Text);
            para.D = System.Text.Encoding.UTF8.GetBytes(textBox9.Text);
            para.Q = System.Text.Encoding.UTF8.GetBytes(textBox10.Text);

            byte[] decBytes = r.Decrypt(bb); //bb is a global byte[] variable
            textBox3.Text = System.Text.Encoding.UTF8.GetString(decBytes, 0, decBytes.Length);

 It throws an error regarding Invalid Key. Can you please let me know what i might be doing wrong.