public async ValueTask <IActionResult> ProcessFile([FromRoute] string method) { var rawFile = Request.Form?.Files; if (rawFile == null) { Log.LogError("Did not recieve file for {method}", method); return(BadRequest($"Did not recieve file for {method}")); } var file = rawFile.First(); using var ms = new MemoryStream(); var newFile = file.CopyToAsync(ms).ConfigureAwait(false); var request = new CryptRequest { File = new FilePayload { FileContent = ms.ToArray() }, Method = method }; var(result, error) = await CryptFileSvc.ProcessFile(request).ConfigureAwait(false); if (error != null) { return(StatusCode(500, error.Exception.Message)); } return(Ok()); }
public void Crypt() { var request = new CryptRequest(GeneralRequests.Crypt); request.Parse(); Assert.Equal("1", request.VersionID); Assert.Equal("gmtest", request.GameName); }
public void Configure(object cryptorInfo) { CryptRequest cryptoDto = cryptorInfo as CryptRequest; des.Mode = (CipherMode)Enum.Parse(typeof(CipherMode), cryptoDto.AlgInfo.CipherMode); des.Padding = (PaddingMode)Enum.Parse(typeof(PaddingMode), cryptoDto.AlgInfo.Padding); des.Key = Convert.FromBase64String(cryptoDto.AlgInfo.Key); des.IV = Convert.FromBase64String(cryptoDto.AlgInfo.IV); }
public void Configure(object cryptorInfo) { CryptRequest cryptoDto = cryptorInfo as CryptRequest; // TODO: implicit conversion? //aes.Mode = (CipherMode)info.CipherMode; // TODO: parse the Mode from Block Chain, or Electronic code book, etc... aes.Mode = (CipherMode)Enum.Parse(typeof(CipherMode), cryptoDto.AlgInfo.CipherMode); aes.Padding = (PaddingMode)Enum.Parse(typeof(PaddingMode), cryptoDto.AlgInfo.Padding); //aes.Key = Encoding.UTF8.GetBytes(info.Key); //aes.IV = Encoding.UTF8.GetBytes(info.IV); aes.Key = Convert.FromBase64String(cryptoDto.AlgInfo.Key); aes.IV = Convert.FromBase64String(cryptoDto.AlgInfo.IV); }
// POST api/values public IHttpActionResult Post([FromBody] CryptRequest cryptDto) { ICryptor cryptor = new CryptorFactory().Instantiate(cryptDto.Operation.Algorithm); cryptor.Configure(cryptDto); var values = cryptor.Handle(cryptDto); var response = new EncryptoResponseDto() { CipherText = values.Item1, Encoding = cryptDto.CipherText.Encoding, Time = values.Item2 }; return(Ok(response)); }
public (string, string) Handle(object cryptoInfo) { CryptRequest cryptDto = cryptoInfo as CryptRequest; Stopwatch stopwatch = new Stopwatch(); string returnValue = null; stopwatch.Start(); if (cryptDto.Operation.Task.Sanitize() == "decrypt") { returnValue = Decrypt(cryptDto.CipherText.Text); } else if (cryptDto.Operation.Task.Sanitize() == "encrypt") { returnValue = Encrypt(cryptDto.ClearText.Text); } stopwatch.Stop(); return(returnValue, stopwatch.Elapsed.ToString()); }
public async ValueTask <(Memory <byte>, ServiceError)> ProcessFile(CryptRequest request) => request switch