Exemple #1
0
        public static System.Security.Cryptography.SHA1 GetGen3RuntimeDataHasher()
        {
            var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            sha1.TransformBlock(kSha1Salt, 0, kSha1Salt.Length, null, 0);
            return(sha1);
        }
Exemple #2
0
        /// <summary>
        /// calculate sha-1 of the audio data
        /// </summary>
        public override byte[] CalculateAudioSHA1()
        {
            using (Stream stream = OpenAudioStream())
            {
                // This is one implementation of the abstract class SHA1.
                System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();

                uint numLeft = _payloadNumBytes;

                const int size  = 4096;
                byte[]    bytes = new byte[4096];
                int       numBytes;

                while (numLeft > 0)
                {
                    // read a whole block, or to the end of the file
                    numBytes = stream.Read(bytes, 0, size);

                    // audio ends on or before end of this read; exit loop and checksum what we have.
                    if (numLeft <= numBytes)
                    {
                        break;
                    }

                    sha.TransformBlock(bytes, 0, size, bytes, 0);
                    numLeft -= (uint)numBytes;
                }

                sha.TransformFinalBlock(bytes, 0, (int)numLeft);

                byte[] result = sha.Hash;
                return(result);
            }
        }
        /// <summary>
        /// calculate sha-1 of the audio data
        /// </summary>
        public override byte[] CalculateAudioSHA1()
        {
            using (Stream stream = OpenAudioStream())
            {
                // This is one implementation of the abstract class SHA1.
                System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();

                uint numLeft = _payloadNumBytes;

                const int size = 4096;
                byte[] bytes = new byte[4096];
                int numBytes;

                while (numLeft > 0)
                {
                    // read a whole block, or to the end of the file
                    numBytes = stream.Read(bytes, 0, size);

                    // audio ends on or before end of this read; exit loop and checksum what we have.
                    if (numLeft <= numBytes)
                        break;

                    sha.TransformBlock(bytes, 0, size, bytes, 0);
                    numLeft -= (uint)numBytes;
                }

                sha.TransformFinalBlock(bytes, 0, (int)numLeft);

                byte[] result = sha.Hash;
                return result;
            }
        }