protected CryptoTransform GetTransform(string peerId) { CryptoTransform transform; lock (_transforms) { if (!_transforms.TryGetValue(peerId, out transform)) { // we prepend RijndaelV1 to peerId to make possible future changes to RijndaelEncryptionProvider logic (for example increasing key or IV size). // if we use unchanged peerId (user id) then it will be impossilbe to store ecnryption keys of different sizes and encryption provider versioning will be broken. var key =_encryptionEncryptionKeyProvider.GetEncryptionKey("RijndaelV1." + peerId, CryptoProvider.KeySize / 8, CryptoProvider.BlockSize / 8); transform = new CryptoTransform(CryptoProvider.CreateEncryptor(key.Key, key.IV), CryptoProvider.CreateDecryptor(key.Key, key.IV)); _transforms.Add(peerId, transform); } } return transform; }