|
| 1 | +// _ __ __ |
| 2 | +// ___ ___ ___ _ __ __| | __ _ | \/ | |
| 3 | +// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| | |
| 4 | +// \__ \\__ \| __/| | | || (_| || (_| || | | | |
| 5 | +// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_| |
| 6 | +// | |
| 7 | +// Copyright 2021-2021 Łukasz "JustArchi" Domeradzki |
| 8 | + |
| 9 | +// | |
| 10 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | +// you may not use this file except in compliance with the License. |
| 12 | +// You may obtain a copy of the License at |
| 13 | +// | |
| 14 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +// | |
| 16 | +// Unless required by applicable law or agreed to in writing, software |
| 17 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +// See the License for the specific language governing permissions and |
| 20 | +// limitations under the License. |
| 21 | + |
| 22 | +using System; |
| 23 | +using System.Diagnostics.CodeAnalysis; |
| 24 | +using JetBrains.Annotations; |
| 25 | +using JustArchiNET.Madness.Helpers; |
| 26 | + |
| 27 | +namespace JustArchiNET.Madness.SHA512Madness; |
| 28 | + |
| 29 | +[MadnessType(EMadnessType.Replacement)] |
| 30 | +[PublicAPI] |
| 31 | +[SuppressMessage("ReSharper", "InconsistentNaming")] |
| 32 | +public static class SHA512 { |
| 33 | + /// <summary> |
| 34 | + /// Computes the hash of data using the SHA512 algorithm. |
| 35 | + /// </summary> |
| 36 | + /// <param name="source">The data to hash.</param> |
| 37 | + /// <returns>The hash of the data.</returns> |
| 38 | + /// <exception cref="ArgumentNullException"> |
| 39 | + /// <paramref name="source" /> is <see langword="null" />. |
| 40 | + /// </exception> |
| 41 | + public static byte[] HashData(byte[] source) { |
| 42 | + if (source == null) { |
| 43 | + throw new ArgumentNullException(nameof(source)); |
| 44 | + } |
| 45 | + |
| 46 | + using System.Security.Cryptography.SHA512 hashAlgorithm = System.Security.Cryptography.SHA512.Create(); |
| 47 | + |
| 48 | + return hashAlgorithm.ComputeHash(source); |
| 49 | + } |
| 50 | +} |
0 commit comments