本文整理汇总了C#中Org.ModPow方法的典型用法代码示例。如果您正苦于以下问题:C# Org.ModPow方法的具体用法?C# Org.ModPow怎么用?C# Org.ModPow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org
的用法示例。
在下文中一共展示了Org.ModPow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsValidPublicKey
/// <summary>
/// Check is the key is valid see RFC 2631, Section 2.1.5, http://www.ietf.org/rfc/rfc2631.txt
/// </summary>
public static bool IsValidPublicKey(Org.BouncyCastle.Math.BigInteger y, Org.BouncyCastle.Math.BigInteger p, Org.BouncyCastle.Math.BigInteger q)
{
Org.BouncyCastle.Math.BigInteger bn;
// y must lie in [2,p-1]
// check y < 2 then failed
bn = new Org.BouncyCastle.Math.BigInteger("2");
if (y.CompareTo(bn) < 0)
{
LibRTMPLogger.Log(LibRTMPLogLevel.Warning, "[CDR.LibRTMP.RTMPHelper.IsValidPublicKey] DH public key must be at least 2");
return false;
}
// y must lie in [2,p-1]
bn = new Org.BouncyCastle.Math.BigInteger(p.ToString());
bn = bn.Subtract(new Org.BouncyCastle.Math.BigInteger("1"));
if (y.CompareTo(bn) > 0)
{
LibRTMPLogger.Log(LibRTMPLogLevel.Warning, "[CDR.LibRTMP.RTMPHelper.IsValidPublicKey] DH public key must be at most p-2");
return false;
}
// Verify with Sophie-Germain prime
//
// This is a nice test to make sure the public key position is calculated
// correctly. This test will fail in about 50% of the cases if applied to
// random data.
bn = y.ModPow(q, p);
if (bn.CompareTo(new Org.BouncyCastle.Math.BigInteger("1")) != 0)
{
LibRTMPLogger.Log(LibRTMPLogLevel.Warning, "[CDR.LibRTMP.RTMPHelper.IsValidPublicKey] DH public key does not fulfill y^q mod p = 1");
return false;
}
return true;
}