I'm trying to encrypt with the Rijndael cipher using built-in .net classes (RijndaelManaged, CryptoStream, etc) The other half of our team are developing with J2ME. For some reason the J2ME team are unable to use an Initialization Vector so we're both encrypting in ECB cipher mode.
My problem is that it seems that the results I'm getting contain extra bytes than the J2ME team (I think that their value is the correct one)
For the text : abcdefghijklmnop
using a key: sXv83E9nGE1sRYVS
My encrypted result: 7O6euhB01dyLyIcrSichwsAMN7z3A5+mIb7W6XPHIY4=
J2ME team encrypted result: 7O6euhB01dyLyIcrSichwg==
Here's the code below. I appreciate any pointers you can give me.
// Rijndael class.RijndaelManaged rijndaelCipher = new RijndaelManaged(); // First we need to turn the input strings into a byte array.byte[] PlainText = System.Text.Encoding.ASCII.GetBytes(InputText);byte[] keyBytes = System.Text.Encoding.ASCII.GetBytes("sXv83E9nGE1sRYVS"); //THE KEY
rijndaelCipher.KeySize = 128;
rijndaelCipher.BlockSize = 128;
rijndaelCipher.Key = keyBytes;
rijndaelCipher.Padding = PaddingMode.PKCS7; //rijndaelCipher.IV //Encoding.ASCII.GetBytes(iv);rijndaelCipher.Mode =
CipherMode.ECB;ICryptoTransform Encryptor = rijndaelCipher.CreateEncryptor(); // Create a MemoryStream that is going to hold the encrypted bytes MemoryStream memoryStream = new MemoryStream(); CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write); // Start the encryption process.
cryptoStream.Write(PlainText, 0, PlainText.Length);
// Finish encrypting.cryptoStream.FlushFinalBlock();
// Convert our encrypted data from a memoryStream into a byte array.byte[] CipherBytes = memoryStream.ToArray(); // Close both streams.memoryStream.Close();
cryptoStream.Close();
string EncryptedData = Convert.ToBase64String(CipherBytes); // Return encrypted string.byte[] encBytes = System.Text.Encoding.ASCII.GetBytes(EncryptedData); string hexText = BytesToHex(CipherBytes); return EncryptedData;Read Full article Here.
No comments:
Post a Comment
Post your comments here: