本文整理汇总了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 { }
}
示例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;
}