コード例 #1
0
ファイル: Key.cs プロジェクト: TheSin-/NBitcoin
        public Key Uncover(Key scan, PubKey ephem)
        {
            AssertNotDiposed();
#if HAS_SPAN
            Span <byte> tmp = stackalloc byte[33];
            ephem.ECKey.GetSharedPubkey(scan._ECKey).WriteToSpan(true, tmp, out _);
            var c    = NBitcoinContext.Instance.CreateECPrivKey(Hashes.SHA256(tmp));
            var priv = c.sec + this._ECKey.sec;
            return(new Key(this._ECKey.ctx.CreateECPrivKey(priv), this.IsCompressed));
#else
            var curve = ECKey.Secp256k1;
            var priv  = new BigInteger(1, PubKey.GetStealthSharedSecret(scan, ephem))
                        .Add(new BigInteger(1, this.ToBytes()))
                        .Mod(curve.N)
                        .ToByteArrayUnsigned();

            if (priv.Length < 32)
            {
                priv = new byte[32 - priv.Length].Concat(priv).ToArray();
            }

            var key = new Key(priv, fCompressedIn: this.IsCompressed);
            return(key);
#endif
        }
コード例 #2
0
ファイル: Key.cs プロジェクト: ppppp-cn/NBitcoin
        public Key Uncover(Key scan, PubKey ephem)
        {
            var curve = ECKey.Secp256k1;
            var priv  = new BigInteger(1, PubKey.GetStealthSharedSecret(scan, ephem))
                        .Add(new BigInteger(1, this.ToBytes()))
                        .Mod(curve.N)
                        .ToByteArrayUnsigned();

            if (priv.Length < 32)
            {
                priv = new byte[32 - priv.Length].Concat(priv).ToArray();
            }

            var key = new Key(priv, fCompressedIn: this.IsCompressed);

            return(key);
        }