Org.BouncyCastle.Crypto.Digests.Sha256Digest.DoFinal C# (CSharp) Method

DoFinal() public method

public DoFinal ( byte output, int outOff ) : int
output byte
outOff int
return int
        public override int DoFinal(
            byte[]  output,
            int     outOff)
        {
            Finish();

            Pack.UInt32_To_BE((uint)H1, output, outOff);
            Pack.UInt32_To_BE((uint)H2, output, outOff + 4);
            Pack.UInt32_To_BE((uint)H3, output, outOff + 8);
            Pack.UInt32_To_BE((uint)H4, output, outOff + 12);
            Pack.UInt32_To_BE((uint)H5, output, outOff + 16);
            Pack.UInt32_To_BE((uint)H6, output, outOff + 20);
            Pack.UInt32_To_BE((uint)H7, output, outOff + 24);
            Pack.UInt32_To_BE((uint)H8, output, outOff + 28);

            Reset();

            return DigestLength;
        }

Usage Example

        /// <summary>
        /// Converts a base-58 string to a byte array, checking the checksum, and
        /// returning null if it wasn't valid.  Appending "?" to the end of the string skips
        /// the checksum calculation, but still strips the four checksum bytes from the
        /// result.
        /// </summary>
        public static byte[] Base58CheckToByteArray(string base58)
        {
            bool IgnoreChecksum = false;
            if (base58.EndsWith("?")) {
                IgnoreChecksum = true;
                base58 = base58.Substring(0, base58.Length - 1);
            }

            byte[] bb = Base58.ToByteArray(base58);
            if (bb == null || bb.Length < 4) return null;

            if (IgnoreChecksum == false) {
                Sha256Digest bcsha256a = new Sha256Digest();
                bcsha256a.BlockUpdate(bb, 0, bb.Length - 4);

                byte[] checksum = new byte[32];  //sha256.ComputeHash(bb, 0, bb.Length - 4);
                bcsha256a.DoFinal(checksum, 0);
                bcsha256a.BlockUpdate(checksum, 0, 32);
                bcsha256a.DoFinal(checksum, 0);

                for (int i = 0; i < 4; i++) {
                    if (checksum[i] != bb[bb.Length - 4 + i]) return null;
                }
            }

            byte[] rv = new byte[bb.Length - 4];
            Array.Copy(bb, 0, rv, 0, bb.Length - 4);
            return rv;
        }
All Usage Examples Of Org.BouncyCastle.Crypto.Digests.Sha256Digest::DoFinal