1 using System.Diagnostics.Contracts;
4 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // <OWNER>[....]</OWNER>
11 // MD5CryptoServiceProvider.cs
14 namespace System.Security.Cryptography {
15 [System.Runtime.InteropServices.ComVisible(true)]
16 public sealed class MD5CryptoServiceProvider : MD5 {
17 [System.Security.SecurityCritical] // auto-generated
18 private SafeHashHandle _safeHashHandle = null;
21 // public constructors
24 [System.Security.SecuritySafeCritical] // auto-generated
25 public MD5CryptoServiceProvider() {
26 if (CryptoConfig.AllowOnlyFipsAlgorithms)
27 throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
28 Contract.EndContractBlock();
30 // _CreateHash will check for failures and throw the appropriate exception
31 _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
34 [System.Security.SecuritySafeCritical] // overrides public transparent member
35 protected override void Dispose(bool disposing)
37 if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
38 _safeHashHandle.Dispose();
39 base.Dispose(disposing);
46 [System.Security.SecuritySafeCritical] // auto-generated
47 public override void Initialize() {
48 if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
49 _safeHashHandle.Dispose();
51 // _CreateHash will check for failures and throw the appropriate exception
52 _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
55 [System.Security.SecuritySafeCritical] // overrides protected transparent member
56 protected override void HashCore(byte[] rgb, int ibStart, int cbSize)
58 Utils.HashData(_safeHashHandle, rgb, ibStart, cbSize);
61 [System.Security.SecuritySafeCritical] // overrides protected transparent member
62 protected override byte[] HashFinal() {
63 return Utils.EndHash(_safeHashHandle);