| | 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 { |
| 0 | 44 | | string md5 = ""; |
| 0 | 45 | | string Output = string.Empty; |
| | 46 | |
|
| | 47 | | void ConvertString() |
| 0 | 48 | | { |
| 0 | 49 | | Output = CreateMD5(md5); |
| 0 | 50 | | } |
| | 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) |
| 0 | 55 | | { |
| | 56 | | // Use input string to calculate MD5 hash |
| 0 | 57 | | using (MD5 md5 = MD5.Create()) |
| 0 | 58 | | { |
| 0 | 59 | | byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input); |
| 0 | 60 | | byte[] hashBytes = md5.ComputeHash(inputBytes); |
| | 61 | |
|
| 0 | 62 | | 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 | | } |
| 0 | 72 | | } |
| | 73 | | } |