I'm trying to setup AES encryption / decryption using the javascript library SlowAES and the RijndaelManaged class in .NET.
I chose this method after reading this post, where Cheeso has managed to get these two encryption methods to play together
"In my tests of the COM-wrapped-SlowAEs, I used CBC mode, and the encryption was completely compatible with the RijndaelManaged class in .NET" - Cheeso
I've taken the javascript code from Cheeso's Windows Scripting Component, the latest slowaes libraries, and using the following javascript script to test:
var key = "12345678901234567890123456789012";
var message = "watson?";
var decrypted;
slowAES.aes.keySize.SIZE_256;
slowAES.modeOfOperation.CBC;
put_PassPhrase(key);
var result = EncryptString(message);
decrypted = DecryptCommaDelimitedStringToString(result)
document.write("Key:" + key + "<br />original:" + message + "<br />Cypher:" + result + "<br />Decrypted:" + decrypted + "<br />IV(): " + get_IV());
I'm getting the following output:
Key:12345678901234567890123456789012
original:watson?
Cypher:245,159,1,1,168,1,1,143,1,1,146,1,1,239,117,1
Decrypted:watson?
IV(): 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
I've modified the following example found on MSDN to try and match the encryption in C# :
public static void Main()
{
try
{
string original = "watson?";
byte[] IV = new byte[16]; // match slowaes IV
byte[] key = new System.Text.ASCIIEncoding().GetBytes("12345678901234567890123456789012");// match slowaes KEY
RijndaelManaged myRijndael = new RijndaelManaged();
myRijndael.BlockSize = 128;
myRijndael.KeySize = 256;
myRijndael.Mode = CipherMode.CBC;
// Encrypt the string to an array of bytes.
byte[] encrypted = encryptStringToBytes_AES(original, key, IV);
// Decrypt the bytes to a string.
string roundtrip = decryptStringFromBytes_AES(encrypted, key, IV);
//Display the original data and the decrypted data.
Console.WriteLine("Original: {0}", original);
Console.WriteLine("Round Trip: {0}", roundtrip);
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
Watch of the byte array:
- encrypted {byte[16]} byte[]
[0] 139 byte
[1] 104 byte
[2] 166 byte
[3] 35 byte
[4] 8 byte
[5] 42 byte
[6] 216 byte
[7] 160 byte
[8] 235 byte
[9] 153 byte
[10] 23 byte
[11] 143 byte
[12] 105 byte
[13] 3 byte
[14] 24 byte
[15] 255 byte
I've tried all the padding options with the managed .NET class, however I can't get the encrypted outputs to match. Can anyone help me?
Thanks,
Bob