Search code examples
javascriptasp.netaesmd5cryptojs

Create CryptoJS AES Cipher Encryptor to Decrypt in .NET


I'm trying to create Encryption/Decryption that will work between server/client. I have CryptoJS for my client side and ASP.Net (VB.Net) for my server side. The server side is being used in numerous places so cannot change so the CryptoJS needs work around what the .NET is doing. I can't get my CryptoJS to imitate the .NET 100%.

FYI the .NET code can't change, the JS has to match .NET functionality.

Code removed upon request

The error I get in .NET when I try and decrypt the client side encryption:

Padding is invalid and cannot be removed.

Extra Information

If I just push through a Hex as the key (remove the .toString(CryptoJS.enc.Latin1)), I don't get enough characters (seems to change to 128bit instead of 256bit).

The actual data returned by MD5_Key in JS seems to match Validate_MD5 in .NET...

Am I trying to achieve the impossible?


Solution

  • CryptoJS supports only AES which is basically Rijndael but limited to the block size of 128-bit. It supports key sizes of 128, 192 and 256-bit. You .net code uses Rijndael with a block size of 256 which is not supported by CryptoJS. CryptoJS happily takes the big IV and only uses the first 16 bytes.

    You will have to find another library that supports this since you can't change the .net code.