ensure thread safety in both encryption logic and tests.