public ActionResult <string> GenerateDigest([FromBody] string request, SigningAlgoritm algoritm = SigningAlgoritm.SHA256WITHRSA) { _logger.LogDebug($"Calling POST /generateDigest{algoritm} endpoint "); if (request == null) { return(BadRequest()); } try { request = DecodeBase64(request); } catch (Exception ex) { _logger.LogError($"Error decoding request data", ex); return(BadRequest("Error decoding request data, check base64 encoding")); } if (algoritm == SigningAlgoritm.SHA256WITHRSA) { return($"SHA-256={Sha256Helper.GenerateHash(request)}"); } else if (algoritm == SigningAlgoritm.SHA512WITHRSA) { return($"SHA-512={Sha512Helper.GenerateHash(request)}"); } else { return(BadRequest($"Unsupported digest algoritm {algoritm}")); } }
public void Basic() { //// https://passwordsgenerator.net/sha256-hash-generator/ var h3 = Sha256Helper.GenerateHash(" "); Assert.AreEqual("36A9E7F1C95B82FFB99743E0C5C4CE95D83C9A430AAC59F84EF3CBFAB6145068", h3); var h4 = Sha256Helper.GenerateHash("sdfgsdfgs"); Assert.AreEqual("D6C84C6D32D245DDA9CE2E9E3C776767DC877B4C2BDEAEC5CAB3E595D573740A", h4); // https://crypto.stackexchange.com/questions/64442/is-it-possible-to-convert-the-output-of-sha256-hash-to-binary-or-decimal-value var h5 = Sha256Helper.GenerateHash("hello world!"); Assert.AreEqual("60668F3A418FF2F78E6C53BC77910B7945ECD29D4B3D9D3934B89B0B5E84F797", h5); }
public async Task <(string data, DateTime updated)> GetData(string url, DownloadOptions options) { string urlHash = Sha256Helper.GenerateHash(url); return(await GetData(url, $"{urlHash}-Data", $"{urlHash}-Updated", options.Expiry, options.CancelToken, options.IgnoreCache).ConfigureAwait(false)); }
public void EmptyString() { var h1 = Sha256Helper.GenerateHash(string.Empty); Assert.AreEqual("E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", h1.ToUpperInvariant()); }
public void Null() { Sha256Helper.GenerateHash(null); }