示例#1
0
        public async Task <IActionResult> DecryptTextAsync([FromBody] EncryptData data)
        {
            if (string.IsNullOrEmpty(data.ClearText))
            {
                return(BadRequest(new { Error = "Please enter a valid plain text" }));
            }
            if (string.IsNullOrEmpty(data.PassPhrase))
            {
                return(BadRequest(new { Error = "Please enter a valid Password" }));
            }
            if (data.Iv.Length > 0 && data.Iv.Length != 16)
            {
                return(BadRequest(new { Error = "Iv Size should be 16" }));
            }
            if (data.KeySize != 128 && data.KeySize != 192 && data.KeySize != 256)
            {
                return(BadRequest(new { Error = "make sure the key size is 128 or 192 or 256" }));
            }
            string plainText = await _encryptionService.DecryptTextAsync(data.ClearText, data.PassPhrase, data.KeySize, data.Iv);

            return(Ok(new { Data = plainText }));
        }