I needed some simple string encryption, so I wrote the following code (with a great deal of \"inspiration\" from here):
    // create and initialize a crypto         
        
Another reason of the exception might be a race condition between several threads using decryption logic - native implementations of ICryptoTransform are not thread-safe (e.g. SymmetricAlgorithm), so it should be put to exclusive section, e.g. using lock. Please refer here for more details: http://www.make-awesome.com/2011/07/system-security-cryptography-and-thread-safety/