0

Possible Duplicate:
Javascript AES encryption

Is there a way to validate an AES encrypted string using javascript or jquery?

function ValidAES(str)
{
    ...
}
ValidAES("U2FsdGVkX1/pnQDBvA08BSX5Dx4X8KdIervCIte1JcU=");//true
ValidAES("@ยท$$%");//false
Community
  • 1
  • 1
Art Grc
  • 453
  • 2
  • 8
  • 14

1 Answers1

3

If your strings were simply AES encrypted, there would be no way to truly validate them -- every string can be decrypted with AES. Most of the results are simply garbage.

In this case, it looks as though your strings are Base64 text. It's not difficult to perform some simple checks to make sure there aren't any invalid characters in there:

return !str.match(/[^A-Za-z0-9+\/=]/);

Note that this will still allow most random user input through, though. This is unavoidable, as some of this user input will be "valid" as far as Javascript can tell. If there is a particular length of AES string that you're expecting, checking string.length might help.