title: System.Security.Cryptography.CryptographicException: Object already exists
body: <p>It's weird. I had this method to encrypt a string:</p>
  
  <pre><code>[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]
  public static string Encrypt(this string stringToEncrypt, string key) {
      var cspp = new CspParameters { 
          KeyContainerName = key, 
          Flags = CspProviderFlags.UseMachineKeyStore 
      };
      var rsa = new RSACryptoServiceProvider(cspp) { 
          PersistKeyInCsp = true 
      };
      var bytes = rsa.Encrypt(System.Text.Encoding.UTF8.GetBytes(stringToEncrypt), true);
      return BitConverter.ToString(bytes);
  }
  </code></pre>
  
  <p>And this was my client:</p>
  
  <pre><code>private const string EncryptionKey = "pezhman";
  
  static Random random = new Random();
  public static int CreateSalt() {
      return random.Next(1000, 9999);
  }
  
  public void EncryptSomething() {
      var salt = CreateSalt();
      var plainText = salt + "," + DateTime.Now;
      var encryptionSaltKey = EncryptionKey + DateTime.Now.Date;
      // here im calling encryptor:
      var encryptedValue = plainText.Encrypt(encryptionSaltKey);
  }
  </code></pre>
  
  <p>I was using this in an <em>ASP.NET MVC 4</em> application. It was working perfectly; but suddenly it stopped working. Actually, in local, I have no problem and it works. But, when I publish my code to the server, I get this error:</p>
  
  <blockquote>
    <p>System.Security.Cryptography.CryptographicException: Object already
    exists.</p>
  </blockquote>
  
  <p>Do you have any idea what's happening here? I know I can <a href="https://stackoverflow.com/a/11445029/645167">grant access to the key to <code>everyone</code></a>. <strong>What I'm asking is</strong>, <em>what just happened at the server? What is changed? What kind of changes can cause the problem?</em></p>