代码位于: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver.cs

private IKey FindDefaultKey(DateTimeOffset now, IEnumerable<IKey> allKeys, out IKey fallbackKey, out bool callerShouldGenerateNewKey)
         {
             // find the preferred default key (allowing for server-to-server clock skew)
             var preferredDefaultKey = (from key in allKeys
                                        where key.ActivationDate <= now + _maxServerToServerClockSkew
                                        orderby key.ActivationDate descending, key.KeyId ascending
                                        select key).FirstOrDefault();

if (preferredDefaultKey != null)
             {
                 _logger.ConsideringKeyWithExpirationDateAsDefaultKey(preferredDefaultKey.KeyId, preferredDefaultKey.ExpirationDate);

// if the key has been revoked or is expired, it is no longer a candidate
                 if (preferredDefaultKey.IsRevoked || preferredDefaultKey.IsExpired(now) || !CanCreateAuthenticatedEncryptor(preferredDefaultKey))
                 {
                     _logger.KeyIsNoLongerUnderConsiderationAsDefault(preferredDefaultKey.KeyId);
                     preferredDefaultKey = null;
                 }
             }

// Only the key that has been most recently activated is eligible to be the preferred default,
             // and only if it hasn't expired or been revoked. This is intentional: generating a new key is
             // an implicit signal that we should stop using older keys (even if they're not revoked), so
             // activating a new key should permanently mark all older keys as non-preferred.

if (preferredDefaultKey != null)
             {
                 // Does *any* key in the key ring fulfill the requirement that its activation date is prior
                 // to the preferred default key's expiration date (allowing for skew) and that it will
                 // remain valid one propagation cycle from now? If so, the caller doesn't need to add a
                 // new key.
                 callerShouldGenerateNewKey = !allKeys.Any(key =>
                    key.ActivationDate <= (preferredDefaultKey.ExpirationDate + _maxServerToServerClockSkew)
                    && !key.IsExpired(now + _keyPropagationWindow)
                    && !key.IsRevoked);

if (callerShouldGenerateNewKey)
                 {
                     _logger.DefaultKeyExpirationImminentAndRepository();
                 }

fallbackKey = null;
                 return preferredDefaultKey;
             }

// If we got this far, the caller must generate a key now.
             // We should locate a fallback key, which is a key that can be used to protect payloads if
             // the caller is configured not to generate a new key. We should try to make sure the fallback
             // key has propagated to all callers (so its creation date should be before the previous
             // propagation period), and we cannot use revoked keys. The fallback key may be expired.
             fallbackKey = (from key in (from key in allKeys
                                         where key.CreationDate <= now - _keyPropagationWindow
                                         orderby key.CreationDate descending
                                         select key).Concat(from key in allKeys
                                                            orderby key.CreationDate ascending
                                                            select key)
                            where !key.IsRevoked && CanCreateAuthenticatedEncryptor(key)
                            select key).FirstOrDefault();

_logger.RepositoryContainsNoViableDefaultKey();

callerShouldGenerateNewKey = true;
             return null;
         }

DataProtection Key的选择的更多相关文章

  1. IIS部署SSL,.crt .key 的证书,怎么部署到IIS,记录一下,以免忘记。

    SSL连接作用不说,百度很多.因为最近想考虑重构一些功能,在登录这块有打算弄成HTTPS的,然后百度了,弄成了,就记录一下,以便以后万一部署的时候忘记掉. 做实验的时候,拿的我个人申请的已经备案的域名 ...

  2. [PHP]基本排序(冒泡排序、快速排序、选择排序、插入排序、二分法排序)

    冒泡排序: function bubbleSort($array){ $len=count($array); //该层循环控制 需要冒泡的轮数 for($i=1;$i<$len;$i++){ / ...

  3. 百度地图开发 Android版应用Key申请

    一 申请API key 在使用百度地图之前,我们必须去申请一个百度地图的API key,申请地址http://lbsyun.baidu.com/apiconsole/key,自己自行注册一个百度账号, ...

  4. Akismet API 密钥(key)免费获取方法

    Akismet插件是用户使用最广泛的垃圾评论插件,也是wordpress的创始人制作的,同时它也毫无疑问的成为wordpress的默认安装插件,这样的插件可以帮助用户解决垃圾评论的烦恼,而且也不用访客 ...

  5. Android 百度地图开发(一)--- 申请API Key和在项目中显示百度地图

      标签: Android百度地图API Key  分类: Android 百度地图开发(2)    最近自己想研究下地图,本来想研究google Map,但是申请API key比较坑爹,于是从百度地 ...

  6. 通过ssh协议实现用户key认证登录

    author:JevonWei 版权声明:原创作品 用户实现key认证登录 主机A 192.168.198,134 主机B 192.168.198,131 主机C 192.168.198,136 创建 ...

  7. PHP算法排序之快速排序、冒泡排序、选择排序、插入排序性能对比

    <?php //冒泡排序 //原理:从倒数第一个数开始,相邻的两个数比较,后面比前面的小,则交换位置,一直到比较第一个数之后则最小的会排在第一位,以此类推 function bubble_sor ...

  8. Xshell配置密钥公钥(Public key)与私钥(Private Key)登录

    ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步:1.生成密钥( ...

  9. Xshell配置ssh免密码登录-密钥公钥(Public key)与私钥(Private Key)登录【已成功实例】

    本文转自https://blog.csdn.net/qjc_501165091/article/details/51278696 ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口 ...

随机推荐

  1. [mysql] ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

    用mysql -u root -p显示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YE ...

  2. Problem 2144 Shooting Game fzu

    Problem 2144 Shooting Game Accept: 99    Submit: 465Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  3. 关于离线底图和离线shp文件的加载

    首先底图是我自己用百度地图18级别的瓦片图在armap中制作的TPK文件,shp图层是我用同样的百度地图18级别的瓦片图矢量化的,二者在arcmap中的空间参考是一致的,所以我以为在移动端加入的时候二 ...

  4. Day4 闭包、装饰器decorator、迭代器与生成器、面向过程编程、三元表达式、列表解析与生成器表达式、序列化与反序列化

    一.装饰器 一.装饰器的知识储备 1.可变长参数  :*args和**kwargs def index(name,age): print(name,age) def wrapper(*args,**k ...

  5. 我的第一个python web开发框架(4)——数据库结构设计与创建

    小白做好前端html设计后,马上开始进入数据库结构设计步骤. 在开始之前,小白回忆了一下老大在公司里培训时讲过的数据库设计解说: 对于初学者来说,很多拿到原型时不知道怎么设计数据表结构,这是很正常的事 ...

  6. 委托、事件、Observer观察者模式的使用解析二

    一.设计模式-Observer观察者模式 Observer设计模式是为了定义对象间的一种一对多的依赖关系,以便于当一个对象的状态改变时,其他依赖于它的对象会被自动告知并更新.Observer模式是一种 ...

  7. ch2-mysql相关

    1 mySql数据库基本 1.1 创建表必须字段 id 1.2 nodeJS数据库连接 根目录下建立 mysql.js 文件代码 var mysql = require('mysql'); var c ...

  8. C# Async/await 异步多线程编程

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  9. css百分比参照大总结

    最近做PC端项目,由于要自适应到800*600,所以免不了要使用百分比的布局方式,但是一开始有点搞不清楚百分比的参照,于是页面的布局怎么调也调不好. 事后我进行了一下总结,希望能够帮到大家: 参照父元 ...

  10. Arrays.asList () 不可添加或删除元素的原因

    Java中奖数组转换为List<T>容器有一个很方便的方法 Arrays.asList(T ... a),我通过此方法给容器进行了赋值操作,接着对其进行 添加元素,却发现会抛出一个(jav ...