コード例 #1
0
        public virtual byte[] GenerateSignature()
        {
            if (forSigning)
            {
                byte[] array = new byte[digest.GetDigestSize()];
                digest.DoFinal(array, 0);
                try
                {
                    BigInteger[] array2 = dsaSigner.GenerateSignature(array);
                    byte[]       array3 = new byte[64];
                    byte[]       array4 = array2[0].ToByteArrayUnsigned();
                    byte[]       array5 = array2[1].ToByteArrayUnsigned();
                    array5.CopyTo(array3, 32 - array5.Length);
                    array4.CopyTo(array3, 64 - array4.Length);
                    return(array3);

IL_0081:
                    byte[] result;
                    return(result);
                }
                catch (Exception ex)
                {
                    throw new SignatureException(ex.Message, ex);
IL_0097:
                    byte[] result;
                    return(result);
                }
            }
            throw new InvalidOperationException("GOST3410DigestSigner not initialised for signature generation.");
        }
コード例 #2
0
        /**
         * Generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public virtual byte[] GenerateSignature()
        {
            if (!forSigning)
            {
                throw new InvalidOperationException("GOST3410DigestSigner not initialised for signature generation.");
            }

            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            try
            {
                BigInteger[] sig      = dsaSigner.GenerateSignature(hash);
                byte[]       sigBytes = new byte[64];

                // TODO Add methods to allow writing BigInteger to existing byte array?
                byte[] r = sig[0].ToByteArrayUnsigned();
                byte[] s = sig[1].ToByteArrayUnsigned();
                s.CopyTo(sigBytes, 32 - s.Length);
                r.CopyTo(sigBytes, 64 - r.Length);
                return(sigBytes);
            }
            catch (Exception e)
            {
                throw new SignatureException(e.Message, e);
            }
        }
コード例 #3
0
        /**
         * Generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public virtual byte[] GenerateSignature()
        {
            if (!forSigning)
            {
                throw new InvalidOperationException("GOST3410DigestSigner not initialised for signature generation.");
            }

            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            try
            {
                BigInteger[] sig = dsaSigner.GenerateSignature(hash);
                if (hash.Length != 32 && hash.Length != 64)
                {
                    throw new InvalidOperationException("Unexpected hash length " + hash.Length);
                }

                // TBD: may be better to pass key size in constructor parameters.
                int    hashSize = hash.Length;              // hash size 32 for 256 bit key and 64 for 512 bit key.
                byte[] sigBytes = new byte[hashSize * 2];

                // TODO Add methods to allow writing BigInteger to existing byte array?
                byte[] r = sig[0].ToByteArrayUnsigned();
                byte[] s = sig[1].ToByteArrayUnsigned();
                s.CopyTo(sigBytes, hashSize - s.Length);
                r.CopyTo(sigBytes, hashSize * 2 - r.Length);
                return(sigBytes);
            }
            catch (Exception e)
            {
                throw new SignatureException(e.Message, e);
            }
        }
コード例 #4
0
 public virtual byte[] GenerateSignature()
 {
     if (!forSigning)
     {
         throw new InvalidOperationException("DSADigestSigner not initialised for signature generation.");
     }
     byte[] array = new byte[digest.GetDigestSize()];
     digest.DoFinal(array, 0);
     BigInteger[] array2 = dsaSigner.GenerateSignature(array);
     return(DerEncode(array2[0], array2[1]));
 }
コード例 #5
0
 public virtual byte[] GenerateSignature()
 {
     //IL_000d: Unknown result type (might be due to invalid IL or missing references)
     if (!forSigning)
     {
         throw new InvalidOperationException("DSADigestSigner not initialised for signature generation.");
     }
     byte[] array = new byte[digest.GetDigestSize()];
     digest.DoFinal(array, 0);
     BigInteger[] array2 = dsaSigner.GenerateSignature(array);
     return(DerEncode(array2[0], array2[1]));
 }
コード例 #6
0
        /**
         * Generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public virtual byte[] GenerateSignature()
        {
            if (!forSigning)
            {
                throw new InvalidOperationException("DSADigestSigner not initialised for signature generation.");
            }

            byte[] hash = BouncyCastle.Utilities.Digests.DoFinal(digest);

            BigInteger[] sig = dsaSigner.GenerateSignature(hash);

            return(DerEncode(sig[0], sig[1]));
        }
コード例 #7
0
        /**
         * Generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public byte[] GenerateSignature()
        {
            if (!forSigning)
            {
                throw new InvalidOperationException("DSADigestSigner not initialised for signature generation.");
            }

            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            BigInteger[] sig = dsaSigner.GenerateSignature(hash);

            return(DerEncode(sig[0], sig[1]));
        }
コード例 #8
0
        /**
         * Generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public byte[] GenerateSignature()
        {
            if (!forSigning)
            {
                throw new InvalidOperationException("GOST3410DigestSigner not initialised for signature generation.");
            }

            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            try
            {
                BigInteger[] sig = dsaSigner.GenerateSignature(hash);
                byte[]       r   = sig[0].ToByteArray();
                byte[]       s   = sig[1].ToByteArray();

                byte[] sigBytes = new byte[64];
                if (s[0] != 0)
                {
                    Array.Copy(s, 0, sigBytes, 32 - s.Length, s.Length);
                }
                else
                {
                    Array.Copy(s, 1, sigBytes, 32 - (s.Length - 1), s.Length - 1);
                }

                if (r[0] != 0)
                {
                    Array.Copy(r, 0, sigBytes, 64 - r.Length, r.Length);
                }
                else
                {
                    Array.Copy(r, 1, sigBytes, 64 - (r.Length - 1), r.Length - 1);
                }

                return(sigBytes);
            }
            catch (Exception e)
            {
                throw new SignatureException(e.Message, e);
            }
        }
コード例 #9
0
ファイル: DsaDigestSigner.cs プロジェクト: zyj0021/bc-csharp
        /**
         * Generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public virtual byte[] GenerateSignature()
        {
            if (!forSigning)
            {
                throw new InvalidOperationException("DSADigestSigner not initialised for signature generation.");
            }

            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);

            BigInteger[] sig = dsa.GenerateSignature(hash);

            try
            {
                return(encoding.Encode(GetOrder(), sig[0], sig[1]));
            }
            catch (Exception)
            {
                throw new InvalidOperationException("unable to encode signature");
            }
        }
コード例 #10
0
 public virtual byte[] GenerateSignature()
 {
     //IL_000d: Unknown result type (might be due to invalid IL or missing references)
     if (!forSigning)
     {
         throw new InvalidOperationException("GOST3410DigestSigner not initialised for signature generation.");
     }
     byte[] array = new byte[digest.GetDigestSize()];
     digest.DoFinal(array, 0);
     try
     {
         BigInteger[] array2 = dsaSigner.GenerateSignature(array);
         byte[]       array3 = new byte[64];
         byte[]       array4 = array2[0].ToByteArrayUnsigned();
         byte[]       array5 = array2[1].ToByteArrayUnsigned();
         ((global::System.Array)array5).CopyTo((global::System.Array)array3, 32 - array5.Length);
         ((global::System.Array)array4).CopyTo((global::System.Array)array3, 64 - array4.Length);
         return(array3);
     }
     catch (global::System.Exception ex)
     {
         throw new SignatureException(ex.get_Message(), ex);
     }
 }
コード例 #11
0
        private void DoTestHMacDetECDsa(IDsa detSigner, IDigest digest, byte[] data, ICipherParameters privKey, BigInteger r, BigInteger s)
        {
            byte[] m = new byte[digest.GetDigestSize()];

            digest.BlockUpdate(data, 0, data.Length);

            digest.DoFinal(m, 0);

            detSigner.Init(true, privKey);

            BigInteger[] rs = detSigner.GenerateSignature(m);

            if (!r.Equals(rs[0]))
            {
                Fail("r value wrong");
            }
            if (!s.Equals(rs[1]))
            {
                Fail("s value wrong");
            }
        }