當前位置: 首頁>>代碼示例>>C#>>正文


C# PgpPublicKey.GetValidSeconds方法代碼示例

本文整理匯總了C#中Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKey.GetValidSeconds方法的典型用法代碼示例。如果您正苦於以下問題:C# PgpPublicKey.GetValidSeconds方法的具體用法?C# PgpPublicKey.GetValidSeconds怎麽用?C# PgpPublicKey.GetValidSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKey的用法示例。


在下文中一共展示了PgpPublicKey.GetValidSeconds方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Load

        private void Load(PgpPublicKey key)
        {
            this.KeyId = key.KeyId.ToString("X");
            if (this.KeyId != null && this.KeyId.Length >= 15)
            {
                this.KeyIdShort = this.KeyId.Substring(this.KeyId.Length - 8);
            }
            this.Algorithm = key.Algorithm.ToString();
            this.BitStrength = key.BitStrength;
            this.IsMasterKey = key.IsMasterKey;
            this.IsEncryptionKey = key.IsEncryptionKey;
            this.Version = key.Version;
            this.CreatedOnUtc = key.CreationTime.ToUniversalTime();

            var validForSeconds = key.GetValidSeconds();
            if(validForSeconds > 0)
            {
                this.Expires = this.CreatedOnUtc.Value.AddSeconds(validForSeconds);
            }

            //this.ValidDays = key.ValidDays;
            //if (this.ValidDays.HasValue)
            //{
            //    this.Expires = this.CreatedOnUtc.Value.AddDays(this.ValidDays.Value);
            //}
            //else
            //{
            //    this.Expires = null;
            //}

            try
            {
                var userIds = key.GetUserIds();
                if (userIds != null)
                {
                    var enumerator = userIds.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        var userIdentity = enumerator.Current as string;
                        if (userIdentity != null && userIdentity.Contains("<") && userIdentity.Contains(">"))
                        {
                            var name = userIdentity.Substring(0, userIdentity.IndexOf("<") - 1).Trim();
                            this.IdentityName = name;
                            var email = userIdentity.Substring(userIdentity.IndexOf("<") + 1);
                            email = email.Substring(0, email.IndexOf(">")).Trim();
                            this.IdentityEmail = email;
                        }
                    }
                }
            }
            catch { }

        }
開發者ID:compliashield,項目名稱:compliashield-sdk-encryption,代碼行數:53,代碼來源:PgpPublicKeyMetaData.cs

示例2: IsKeyValid

		/// <summary>
		/// Perform basic validation of key. Check if revoked or expired.
		/// </summary>
		/// <param name="pubKey"></param>
		/// <returns></returns>
		public bool IsKeyValid(PgpPublicKey pubKey)
		{
			if (pubKey.IsRevoked())
				return false;

			// Check if key has expired
			if (pubKey.GetValidSeconds() != 0)
			{
				var expireTime = pubKey.CreationTime.AddSeconds(pubKey.GetValidSeconds());
				if (DateTime.Now > expireTime)
					return false;
			}

			return true;
		}
開發者ID:ALange,項目名稱:OutlookPrivacyPlugin,代碼行數:20,代碼來源:PgpCrypto.cs


注:本文中的Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKey.GetValidSeconds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。