I sincerely hope someone can help me out.
I'm attempting to use Mcrypt to encrypt strings of text using a PHP script using a randomly-generated key, which I then store until I need to decrypt the string.
My random keys are of random length, usually between 8 - 64 characters in length. They include random characters (upper or lower-case) and random numbers.
My plaintext are strings of 'normal' text. Sentences, for example. They are obviously of random length as well.
When I encrypt the code using the key, it appears to work fine. The problem arises when I try and decrypt the ciphertext using the same key. The problem is that decrypting success also seems to be completely random. Sometimes it WILL decrypt properly, sometimes it won't decrypt at all (it will return 'garbage'), or sometimes it begins decrypting a few characters properly, then it dies and continues with garbage.
Needless to say, I'm pretty choked about the randomness of the results I've been having. I admit that I'm a newbie when it comes to encryption, but I always thought that the idea of 'using the same key to encrypt and decrypt a message' would work regardless. Apparently not. Unfortunately, the documentation in both the PHP Manual and the mcrypt man pages don't do anything to introduce you how to properly use mcrypt, and there are few other resources that address the issue. They all assume that if you're using mcrypt, you're a master at encryption.
So my question is, does anyone know what I might be doing wrong or where I might be able to go for a decent introduction to using mcrypt?
I'd sincerely appreciate any help or direction anyone can provide me.
Thank You,