Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / mscorlib / system / security / cryptography / md5cryptoserviceprovider.cs
1 using System.Diagnostics.Contracts;
2 // ==++==
3 // 
4 //   Copyright (c) Microsoft Corporation.  All rights reserved.
5 // 
6 // ==--==
7 // <OWNER>[....]</OWNER>
8 // 
9
10 //
11 // MD5CryptoServiceProvider.cs
12 //
13
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;
19
20         //
21         // public constructors
22         //
23
24         [System.Security.SecuritySafeCritical]  // auto-generated
25         public MD5CryptoServiceProvider() {
26             if (CryptoConfig.AllowOnlyFipsAlgorithms)
27                 throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
28             Contract.EndContractBlock();
29
30             // _CreateHash will check for failures and throw the appropriate exception
31             _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
32         }
33
34         [System.Security.SecuritySafeCritical] // overrides public transparent member
35         protected override void Dispose(bool disposing)
36         {
37             if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
38                 _safeHashHandle.Dispose();
39             base.Dispose(disposing);
40         }
41
42         //
43         // public methods
44         //
45
46         [System.Security.SecuritySafeCritical]  // auto-generated
47         public override void Initialize() {
48             if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
49                 _safeHashHandle.Dispose();
50             
51             // _CreateHash will check for failures and throw the appropriate exception
52             _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_MD5);
53         }
54
55         [System.Security.SecuritySafeCritical] // overrides protected transparent member
56         protected override void HashCore(byte[] rgb, int ibStart, int cbSize)
57         {
58             Utils.HashData(_safeHashHandle, rgb, ibStart, cbSize);
59         }
60
61         [System.Security.SecuritySafeCritical] // overrides protected transparent member
62         protected override byte[] HashFinal() {
63             return Utils.EndHash(_safeHashHandle);
64         }
65     }
66 }