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


C# BigInteger.GetBytes方法代码示例

本文整理汇总了C#中Granados.Mono.Math.BigInteger.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.GetBytes方法的具体用法?C# BigInteger.GetBytes怎么用?C# BigInteger.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Granados.Mono.Math.BigInteger的用法示例。


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

示例1: AsUInt64

 private static ulong AsUInt64(BigInteger num)
 {
     int bits = num.BitCount();
     if (bits >= 64)
         throw new ArgumentException("too large BigInteger value");
     byte[] data = num.GetBytes();
     ulong val = 0;
     foreach (byte b in data) {
         val = (val << 8) | b;
     }
     return val;
 }
开发者ID:yiyi99,项目名称:poderosa,代码行数:12,代码来源:DSA.cs

示例2: StripPKCS1Pad

        /// <summary>
        /// Extract an message from the encoded message (EM) described in PKCS#1
        /// </summary>
        /// <param name="input">encoded message bits</param>
        /// <param name="type">type number (1 or 2)</param>
        /// <returns>message bits</returns>
        public static BigInteger StripPKCS1Pad(BigInteger input, int type)
        {
            byte[] strip = input.GetBytes();
            int stripLen = strip.Length;

            int i = 0;
            while (true) {
                if (i >= stripLen) {
                    throw new ArgumentException("Invalid EM format");
                }
                if (strip[i] != 0) {
                    break;
                }
                i++;
            }

            if (strip[i] != type) {
                throw new ArgumentException(String.Format("Invalid PKCS1 padding {0}", type));
            }
            i++;

            int padLen = 0;
            while (true) {
                if (i >= stripLen) {
                    throw new ArgumentException("Invalid EM format");
                }
                byte b = strip[i];
                if (b == 0) {
                    break;
                }
                if (type == 1 && b != 0xff) {
                    throw new ArgumentException("Invalid PKCS1 padding");
                }
                padLen++;
                i++;
            }

            if (padLen < 8) {
                throw new ArgumentException("Invalid PKCS1 padding");
            }

            i++;    // skip 0x00
            if (i >= stripLen) {
                throw new ArgumentException("Invalid PKCS1 padding, corrupt data");
            }

            byte[] val = new byte[stripLen - i];
            Buffer.BlockCopy(strip, i, val, 0, val.Length);
            return new BigInteger(val);
        }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:56,代码来源:RSA.cs

示例3: SignWithSHA1

        public byte[] SignWithSHA1(byte[] data)
        {
            byte[] hash = new SHA1CryptoServiceProvider().ComputeHash(data);

            byte[] buf = new byte[hash.Length + PKIUtil.SHA1_ASN_ID.Length];
            Array.Copy(PKIUtil.SHA1_ASN_ID, 0, buf, 0, PKIUtil.SHA1_ASN_ID.Length);
            Array.Copy(hash, 0, buf, PKIUtil.SHA1_ASN_ID.Length, hash.Length);

            BigInteger x = new BigInteger(buf);
            //Debug.WriteLine(x.ToString(16));
            int padLen = (_publickey._n.BitCount() + 7) / 8;

            BigInteger xx = RSAUtil.PKCS1PadType1(x.GetBytes(), padLen);
            byte[] result = Sign(xx.GetBytes());
            return result;
        }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:16,代码来源:RSA.cs

示例4: PointMul

        /// <summary>
        /// Point multiplication over the curve
        /// </summary>
        private bool PointMul(
                BigInteger.ModulusRing ring,
                ECPoint p1,
                BigInteger k,
                out ECPoint p2) {

            //
            // Windowed method
            //

            const int W = 4;
            const uint TPW = 1u << W;   // 2^W

            // precompute point multiplication : {1 .. 2^W-1}P.
            // array is allocated for {0 .. 2^W-1}P, and index 0 is never used.
            ECPoint[] precomp = new ECPoint[TPW];

            {
                ECPoint t = p1;
                precomp[1] = t;
                if (!PointDouble(ring, t, out t)) {
                    goto Failure;
                }
                precomp[2] = t;
                for (uint i = 3; i < TPW; ++i) {
                    if (!PointAdd(ring, t, p1, out t)) {
                        goto Failure;
                    }
                    precomp[i] = t;
                }
            }

            byte[] bits = k.GetBytes();

            ECPoint p = null;

            foreach (byte b in bits) {
                for (int f = 0; f < 2; ++f) {
                    if (p != null) {
                        for (int i = 0; i < 4; ++i) {
                            if (!PointDouble(ring, p, out p)) {
                                goto Failure;
                            }
                        }
                    }

                    int precompIndex = (f == 0) ? (b >> 4) : (b & 0xf);
                    if (precompIndex != 0) {
                        if (p != null) {
                            if (!PointAdd(ring, p, precomp[precompIndex], out p)) {
                                goto Failure;
                            }
                        }
                        else {
                            p = precomp[precompIndex];
                        }
                    }
                }
            }

            if (p == null) {
                // case of k = 0
                goto Failure;
            }

            // succeeded
            p2 = p;
            return true;

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

示例5: PointMul

 /// <summary>
 /// Point multiplication
 /// </summary>
 /// <param name="k">scalar value</param>
 /// <param name="p">point</param>
 /// <returns>result</returns>
 private Ed25519Point PointMul(BigInteger k, Ed25519Point p)
 {
     Ed25519Point mp = p;
     Ed25519Point q = new Ed25519Point(0, 1, 1, 0);  // Neutral element
     int kBitCount = k.BitCount();
     byte[] kBytes = k.GetBytes();
     int kOffset = kBytes.Length - 1;
     for (int i = 0; i < kBitCount; ++i) {
         if (i > 0) {
             mp = PointAdd(mp, mp);
         }
         if ((kBytes[kOffset - i / 8] & (byte)(1 << (i % 8))) != 0) {
             q = PointAdd(q, mp);
         }
     }
     return q;
 }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:23,代码来源:ED.cs


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