GetValidSeconds() public method

The number of valid seconds from creation time - zero means no expiry.
public GetValidSeconds ( ) : long
return long
        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 { }

        }
Esempio n. 2
0
		/// <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;
		}