Is there a way to encrypt data in javascript using CBC/PKCS7 so that it can be decrypted in php or .NET?
I've experimented with slowAES, but the encrypted output doesn't seem to be correct.
When I compare slowAES and .NET encryption using the same input byte arrays (key, iv, and message), slowAES produces a different output byte array.
Comparing the results with .NET and php's mcrypt, they generate the same output.
I attempted to apply the fix suggested in this link, but it didn't resolve the issue.
If this is indeed a problem with slowAES, does anyone know of a functional alternative or how to address it?
On a side note, I am able to successfully encrypt and decrypt when only using slowAES.
Update: Here's an example:
JavaScript Encryption:
var bytesToEncrypt = cryptoHelpers.convertStringToByteArray("2|2010-11-23+10:04:53|0");
var key = cryptoHelpers.base64.decode("de1310982b646af063e7314e8ddd4787");
var iv = cryptoHelpers.base64.decode("v/VCTAlV5+kexBFN16WY5A==");
var result = slowAES.encrypt(bytesToEncrypt,
slowAES.modeOfOperation.CBC,
key,
slowAES.aes.keySize.SIZE_128,
iv);
return result['cipher'];
.NET/Silverlight Encryption:
class AES
{
AesManaged aes;
public AES(string base64key, string base64IV)
: this(Convert.FromBase64String(base64key),Convert.FromBase64String(base64IV))
{}
public AES(byte[] key, byte[] iv)
{
// CBC/128/PKCS7
aes = new AesManaged();
aes.Key = key;
aes.IV = iv;
}
public string Encrypt(string strInptData)
{
byte[] utfdata = UTF8Encoding.UTF8.GetBytes(strInptData);
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
// Create the streams used for encryption.
MemoryStream msEncrypt = new MemoryStream();
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
csEncrypt.Write(utfdata, 0, utfdata.Length);
csEncrypt.Flush();
csEncrypt.Close();
// Showing our encrypted content
byte[] encryptBytes = msEncrypt.ToArray();
return HttpUtility.UrlEncode(Convert.ToBase64String(encryptBytes));
}
}
string base64key = "de1310982b646af063e7314e8ddd4787";
string base64iv = "v/VCTAlV5+kexBFN16WY5A==";
aes = new AES(base64key, base64iv);
auth_token = aes.Encrypt("2|2010-11-23+10:04:53|0");
The comparison reveals that .NET and JavaScript produce different byte arrays, indicating that the issue may not be related to base64/url encoding/decoding.