grip003 Posted March 26, 2007 Posted March 26, 2007 I wrote a simple encryption class to handle encrypting strings and byte arrays. Everything works perfectly in Windows XP and Windows 2000, but I get the following error in Windows 98: Byte array is too large. The maximum size byte array that can be encrypted by this public key implementation is 16 bytes. I am getting this error in the following code public static byte[] RSAEncrypt(byte[] DataToEncrypt, string key_file) { // Encryption is done using the public key. try { System.Windows.Forms.MessageBox.Show("Creating " + "RSACryptoServiceProvider."); // Create a new instance of RSACryptoServiceProvider RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); // Import the RSA Key information, which only needs to // include the public key information. System.IO.FileStream reader = new System.IO.FileStream( key_file, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.Xml.XmlTextReader xml_reader = new System.Xml.XmlTextReader(reader); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(xml_reader); xml_reader.Close(); reader.Close(); RSA.FromXmlString(doc.InnerXml); // By default this will create a 128 bit AES object SymmetricAlgorithm sa = SymmetricAlgorithm.Create(); ICryptoTransform ct = sa.CreateEncryptor(); byte[] encrypt = ct.TransformFinalBlock( DataToEncrypt, 0, DataToEncrypt.Length); RSAPKCS1KeyExchangeFormatter fmt = new RSAPKCS1KeyExchangeFormatter(RSA); byte[] keyex = fmt.CreateKeyExchange(sa.Key); // return the key exchange, the IV (public) and encrypted data byte[] result = new byte [keyex.Length + sa.IV.Length + encrypt.Length]; Buffer.BlockCopy(keyex, 0, result, 0, keyex.Length); Buffer.BlockCopy(sa.IV, 0, result, keyex.Length, sa.IV.Length); Buffer.BlockCopy(encrypt, 0, result, keyex.Length + sa.IV.Length, encrypt.Length); return result; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Exception!!\n" + ex.Message); return null; } }// end RSAEncrypt(byte[] DataToEncrypt, string key_file) The error comes on line byte[] keyex = fmt.CreateKeyExchange(sa.Key); I have I.E. 6.0 installed on the 98 machine, which should include the strong encryption that I need, at least that's what I've heard. Can anyone help me out here? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.