当前位置: 首页>>代码示例>>C#>>正文


C# ECPoint类代码示例

本文整理汇总了C#中ECPoint的典型用法代码示例。如果您正苦于以下问题:C# ECPoint类的具体用法?C# ECPoint怎么用?C# ECPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ECPoint类属于命名空间,在下文中一共展示了ECPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DecipherKey

        public byte[] DecipherKey(BigInteger privateKey, ECPoint tag)
        {
            var keyPoint = tag.Multiply(privateKey);
            var key = SHA256.DoubleHash(keyPoint.EncodePoint(false));

            return key;
        }
开发者ID:TangibleCryptography,项目名称:Secp256k1,代码行数:7,代码来源:ECElGamal.cs

示例2: Parse

        /// <summary>
        /// Parses an elliptic curve point.
        /// </summary>
        /// <param name="data">octet data</param>
        /// <param name="ec">elliptic curve domain parameters</param>
        /// <param name="p">an elliptic curve point object</param>
        /// <returns>true if parsing and validation succeeded</returns>
        public static bool Parse(byte[] data, EllipticCurve ec, out ECPoint p) {
            if (IsZero(data)) {
                // point at infinity
                p = null;
                return false;
            }

            if (data.Length < 2) {
                // invalid length
                p = null;
                return false;
            }

            if (data[0] == 0x04) {
                ECPoint tmp = ParseUncompressed(data);
                if (tmp == null) {
                    p = null;
                    return false;
                }
                if (!ec.ValidatePoint(tmp)) {
                    p = null;
                    return false;
                }
                p = tmp;
                p.Validated = true;
                return true;
            }

            // Compressed form of EC point is not supported.
            // OpenSSL, which is used by OpenSSH for cryptography, disables
            // EC point compression by default due to the patent reason.

            p = null;
            return false;
        }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:42,代码来源:EC.cs

示例3: MultiplyPositive

        protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
        {
            ECCurve curveOrig = p.Curve;

            ECCurve curveAdd = ConfigureCurve(curveOrig, additionCoord);
            ECCurve curveDouble = ConfigureCurve(curveOrig, doublingCoord);

            int[] naf = WNafUtilities.GenerateCompactNaf(k);

            ECPoint Ra = curveAdd.Infinity;
            ECPoint Td = curveDouble.ImportPoint(p);

            int zeroes = 0;
            for (int i = 0; i < naf.Length; ++i)
            {
                int ni = naf[i];
                int digit = ni >> 16;
                zeroes += ni & 0xFFFF;

                Td = Td.TimesPow2(zeroes);

                ECPoint Tj = curveAdd.ImportPoint(Td);
                if (digit < 0)
                {
                    Tj = Tj.Negate();
                }

                Ra = Ra.Add(Tj);

                zeroes = 1;
            }

            return curveOrig.ImportPoint(Ra);
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:34,代码来源:MixedNafR2LMultiplier.cs

示例4: GenerateKey

        public ECPoint GenerateKey(ECPoint publicKey, out byte[] key, BigInteger? k)
        {
            for (int i = 0; i < 100; i++)
            {
                if (k == null)
                {
                    byte[] kBytes = new byte[33];
                    rngCsp.GetBytes(kBytes);
                    kBytes[32] = 0;

                    k = new BigInteger(kBytes);
                }

                if (k.Value.IsZero || k.Value >= Secp256k1.N) continue;

                var tag = Secp256k1.G.Multiply(k.Value);
                var keyPoint = publicKey.Multiply(k.Value);

                if (keyPoint.IsInfinity || tag.IsInfinity) continue;

                key = SHA256.DoubleHash(keyPoint.EncodePoint(false));

                return tag;
            }

            throw new Exception("Unable to generate key");
        }
开发者ID:TangibleCryptography,项目名称:Secp256k1,代码行数:27,代码来源:ECElGamal.cs

示例5: Multiply

		/**
		* D.3.2 pg 101
		* @see org.bouncycastle.math.ec.multiplier.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
		*/
		public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
		{
			// TODO Probably should try to add this
			// BigInteger e = k.Mod(n); // n == order of p
			BigInteger e = k;
			BigInteger h = e.Multiply(BigInteger.Three);

			ECPoint neg = p.Negate();
			ECPoint R = p;

			for (int i = h.BitLength - 2; i > 0; --i)
			{             
				R = R.Twice();

				bool hBit = h.TestBit(i);
				bool eBit = e.TestBit(i);

				if (hBit != eBit)
				{
					R = R.Add(hBit ? p : neg);
				}
			}

			return R;
		}
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:29,代码来源:FpNafMultiplier.cs

示例6: Encrypt

        public byte[] Encrypt(ECPoint publicKey, byte[] data)
        {
            byte[] key;
            var tag = ecElGamal.GenerateKey(publicKey, out key);
            var tagBytes = tag.EncodePoint(false);

            byte[] iv = new byte[16];
            rngCsp.GetBytes(iv);

            aesEncryption.IV = iv;

            aesEncryption.Key = key;

            ICryptoTransform crypto = aesEncryption.CreateEncryptor();

            byte[] cipherData = crypto.TransformFinalBlock(data, 0, data.Length);

            byte[] cipher = new byte[cipherData.Length + 65 + 16];

            Buffer.BlockCopy(tagBytes, 0, cipher, 0, 65);
            Buffer.BlockCopy(aesEncryption.IV, 0, cipher, 65, 16);
            Buffer.BlockCopy(cipherData, 0, cipher, 65 + 16, cipherData.Length);

            return cipher;
        }
开发者ID:schalk-b,项目名称:bitsy,代码行数:25,代码来源:ECEncryption.cs

示例7: PublicKey

 public PublicKey(ECPoint point)
 {
     this.IsCompressedPoint = point.IsCompressed;
     this.point = point;
     this.PublicKeyBytes = point.GetEncoded();
     if (validatePoint() == false) throw new ArgumentException("Not a valid public key");
 }
开发者ID:Groestlcoin,项目名称:Groestlcoin-Address-Utility,代码行数:7,代码来源:PublicKey.cs

示例8: CreateSignatureRedeemScript

 public static byte[] CreateSignatureRedeemScript(ECPoint publicKey)
 {
     using (ScriptBuilder sb = new ScriptBuilder())
     {
         sb.Push(publicKey.EncodePoint(true));
         sb.Add(ScriptOp.OP_CHECKSIG);
         return sb.ToArray();
     }
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:9,代码来源:SignatureContract.cs

示例9: Create

 public static SignatureContract Create(ECPoint publicKey)
 {
     return new SignatureContract
     {
         RedeemScript = CreateSignatureRedeemScript(publicKey),
         PublicKeyHash = publicKey.EncodePoint(true).ToScriptHash(),
         publicKey = publicKey
     };
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:9,代码来源:SignatureContract.cs

示例10: PointDoubling

        public void PointDoubling(
			BigInteger x1, BigInteger y1,
			BigInteger x2, BigInteger y2)
        {
            var p = new ECPoint(x1, y1);
            var expected = new ECPoint(x2, y2);

            Assert.True(expected == 2*p);
        }
开发者ID:lontivero,项目名称:BitcoinLite,代码行数:9,代码来源:Secp256k1Tests.cs

示例11: Multiply

        public virtual ECPoint Multiply(ECPoint p, BigInteger k)
        {
            int sign = k.SignValue;
            if (sign == 0 || p.IsInfinity)
                return p.Curve.Infinity;

            ECPoint positive = MultiplyPositive(p, k.Abs());
            return sign > 0 ? positive : positive.Negate();
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:9,代码来源:AbstractECMultiplier.cs

示例12: ECCurve

 private ECCurve(BigInteger Q, BigInteger A, BigInteger B, BigInteger N, byte[] G)
 {
     this.Q = Q;
     this.A = new ECFieldElement(A, this);
     this.B = new ECFieldElement(B, this);
     this.N = N;
     this.Infinity = new ECPoint(null, null, this);
     this.G = ECPoint.DecodePoint(G, this);
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:9,代码来源:ECCurve.cs

示例13: PointAddition

        public void PointAddition(
			BigInteger x1, BigInteger y1,
			BigInteger x2, BigInteger y2,
			BigInteger x3, BigInteger y3)
        {
            var p1 = new ECPoint(x1, y1);
            var p2 = new ECPoint(x2, y2);
            var expected = new ECPoint(x3, y3);

            Assert.True(expected == p1 + p2);
        }
开发者ID:lontivero,项目名称:BitcoinLite,代码行数:11,代码来源:Secp256k1Tests.cs

示例14: MultiplyPositive

        /**
         * Joye's double-add algorithm.
         */
        protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
        {
            ECPoint[] R = new ECPoint[]{ p.Curve.Infinity, p };

            int n = k.BitLength;
            for (int i = 0; i < n; ++i)
            {
                int b = k.TestBit(i) ? 1 : 0;
                int bp = 1 - b;
                R[bp] = R[bp].TwicePlus(R[b]);
            }

            return R[0];
        }
开发者ID:bitcoinkit,项目名称:BitcoinKit-CSharp,代码行数:17,代码来源:DoubleAddMultiplier.cs

示例15: Add

 public bool Add(byte[] redeemScript, ECPoint pubkey, byte[] signature)
 {
     UInt160 scriptHash = redeemScript.ToScriptHash();
     for (int i = 0; i < ScriptHashes.Length; i++)
     {
         if (ScriptHashes[i] == scriptHash)
         {
             if (signatures[i] == null)
                 signatures[i] = new MultiSigContext(redeemScript);
             return signatures[i].Add(pubkey, signature);
         }
     }
     return false;
 }
开发者ID:bityuan,项目名称:AntShares,代码行数:14,代码来源:SignatureContext.cs


注:本文中的ECPoint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。