Произошла ошибка во время криптографической операции на веб-сайте с использованием Azure Active Directory - PullRequest
0 голосов
/ 26 апреля 2018

Я использую Azure Active Directory для входа на свой веб-сайт.

При первом входе в систему все в порядке, но через некоторое время, когда мы делаем обновление, мы получаем сообщение об ошибке:

Произошла ошибка во время криптографической операции. CryptographicException: ошибка произошла во время криптографической операции.] System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors (Func`2 func, Byte [] input) +175 Web.Models.ADALTokenCache..ctor (String signatureInUserId) в Web \ Models \ AdalTokenCache.cs: 30

Я искал и нашел несколько решений, но ни одно из них не работает:

BeforeAccessNotification:

       try
        {
            this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits, "ADALCache"));
        }
        catch (System.Security.Cryptography.CryptographicException cge)
        {
            db.UserTokenCaches.Remove(Cache);
            db.SaveChanges();
        }

AfterAccessNotification:

            if (Cache == null)
            {
                Cache = new UserTokenCache
                {
                    webUserUniqueId = userId,
                    cacheBits = MachineKey.Protect(this.Serialize(), 
                    "ADALCache"),
                    LastWrite = DateTime.Now
                };
            }

            //Cache.cacheBits = MachineKey.Protect(this.Serialize(), 
             "ADALCache");
            //Cache.LastWrite = DateTime.Now;

            // update the DB and the lastwrite 
            db.Entry(Cache).State = Cache.UserTokenCacheId == 0 ? 
            EntityState.Added : EntityState.Modified;
            db.SaveChanges();
            this.HasStateChanged = false;

1 Ответ

0 голосов
/ 30 апреля 2018
   public ADALTokenCache(string signedInUserId)
    {
        // associate the cache to the current user of the web app
        userId = signedInUserId;
        this.AfterAccess = AfterAccessNotification;
        this.BeforeAccess = BeforeAccessNotification;
        this.BeforeWrite = BeforeWriteNotification;
        // look up the entry in the database
        Cache = db.UserTokenCaches.FirstOrDefault(c => c.webUserUniqueId == userId);
        // place the entry in memory
        this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits,"ADALCache"));
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...