< Summary

Information
Class: Utility.Components.MD5Converter.MD5Converter
Assembly: Utility
File(s): /home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Components/MD5Converter/MD5Converter.razor
Tag: 231_14069517506
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 73
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
ConvertString()100%210%
CreateMD5(...)100%210%

File(s)

/home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Components/MD5Converter/MD5Converter.razor

#LineLine coverage
 1@using System.Security.Cryptography
 2
 3<div class="container">
 4
 5    <div class="row">
 6        <div class="col">
 7            <p>⛔️<a href="https://learn.microsoft.com/en-us/dotnet/core/compatibility/cryptography/5.0/cryptography-apis
 8            <p><code>System.Security.Cryptography.Algorithms is not supported on this platform.</code></p>
 9        </div>
 10    </div>
 11
 12    <div class="row">
 13        <div class="col">
 14
 15            <label class="label-control">String:</label>
 16            <div class="input-group">
 17                <input id="ascii" name="md5" class="form-control" @bind="md5" placeholder="">
 18                <span class="input-group-btn">
 19                    <button id="btnConvert" name="btnConvert" type="button" class="btn btn-success float-right" @onclick
 20                </span>
 21            </div>
 22
 23        </div>
 24    </div>
 25
 26    <br/>
 27
 28    <div class="row">
 29        <div class="col">
 30            <textarea id="Output" name="Output" class="form-control" rows="5" @bind="Output"></textarea>
 31        </div>
 32    </div>
 33
 34    @* <hr/> *@
 35
 36    @* <div class="row"> *@
 37    @*     <div class="col"> *@
 38    @*         <p>Inspired from <a href="" target="_blank"></a></p> *@
 39    @*     </div> *@
 40    @* </div> *@
 41</div>
 42
 43@code {
 044    string md5 = "";
 045    string Output = string.Empty;
 46
 47    void ConvertString()
 048    {
 049        Output = CreateMD5(md5);
 050    }
 51
 52    // https://stackoverflow.com/a/24031467/2895831
 53    // https://msdn.microsoft.com/en-us/library/system.security.cryptography.md5%28v=vs.110%29.aspx
 54    public static string CreateMD5(string input)
 055    {
 56    // Use input string to calculate MD5 hash
 057        using (MD5 md5 = MD5.Create())
 058        {
 059            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
 060            byte[] hashBytes = md5.ComputeHash(inputBytes);
 61
 062            return Convert.ToHexString(hashBytes); // .NET 5 +
 63
 64            // Convert the byte array to hexadecimal string prior to .NET 5
 65            // StringBuilder sb = new System.Text.StringBuilder();
 66            // for (int i = 0; i < hashBytes.Length; i++)
 67            // {
 68            //     sb.Append(hashBytes[i].ToString("X2"));
 69            // }
 70            // return sb.ToString();
 71        }
 072    }
 73}