File: system\security\cryptography\md5cryptoserviceprovider.cs
Project: ndp\clr\src\bcl\mscorlib.csproj (mscorlib)
using System.Diagnostics.Contracts;
// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
// <OWNER>Microsoft</OWNER>
// 
 
//
// MD5CryptoServiceProvider.cs
//
 
namespace System.Security.Cryptography {
[System.Runtime.InteropServices.ComVisible(true)]
    public sealed class MD5CryptoServiceProvider : MD5 {
        [System.Security.SecurityCritical] // auto-generated
        private SafeHashHandle _safeHashHandle = null;
 
        //
        // public constructors
        //
 
        [System.Security.SecuritySafeCritical]  // auto-generated
        public MD5CryptoServiceProvider() {
            // .NET Framework 2.0 - 4.7.2 rejected MD5 when in FIPS mode because it was not
            // an approved algorithm.  Since this caused problems for legitimate applications
            // this is no longer done, an application or library needs to determine on its own
            // if MD5 is prohibited in context.
            if (CryptoConfig.AllowOnlyFipsAlgorithms && AppContextSwitches.UseLegacyFipsThrow)
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            Contract.EndContractBlock();
 
            // _CreateHash will check for failures and throw the appropriate exception
            _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
        }
 
        [System.Security.SecuritySafeCritical] // overrides public transparent member
        protected override void Dispose(bool disposing)
        {
            if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
                _safeHashHandle.Dispose();
            base.Dispose(disposing);
        }
 
        //
        // public methods
        //
 
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override void Initialize() {
            if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
                _safeHashHandle.Dispose();
            
            // _CreateHash will check for failures and throw the appropriate exception
            _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
        }
 
        [System.Security.SecuritySafeCritical] // overrides protected transparent member
        protected override void HashCore(byte[] rgb, int ibStart, int cbSize)
        {
            Utils.HashData(_safeHashHandle, rgb, ibStart, cbSize);
        }
 
        [System.Security.SecuritySafeCritical] // overrides protected transparent member
        protected override byte[] HashFinal() {
            return Utils.EndHash(_safeHashHandle);
        }
    }
}