Decryption fails when a running thread culture is set to tr-TR (Turkish)

Issue #3 new
obviex repo owner created an issue

The problem seems to occur when a running thread dynamically changes the culture, using the following code:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("tr-TR");
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("tr-TR");

This may cause the "Decryption failed" exception (with "Padding is invalid and cannot be removed" details).

Comments (1)

  1. obviex reporter
    • edited description

    There may be a couple of workarounds . One option would be to use CipherSafe before a call to create tr-TR culture is made on the worker thread. If this is not possible, you can save the tr-TR thread info, switch the thread culture temporarily to invariant, invoke a CipherSafe API, and then switch the thread culture back to tr-TR, as illustrated in this example (from [Writing Culture-Safe Managed Code (http://msdn.microsoft.com/en-us/library/ms994325.aspx); see the Alternative Techniques section):

    static void SwitchExample() {
        CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        try {
            DoSomething();
        }
        finally {
            Thread.CurrentThread.CurrentCulture = originalCulture;                
        }
    }
    
  2. Log in to comment