public void Bit_Convert_Test()
        {
            var stego     = new Stego(FileHelper.GetPathToImage());
            var fileBytes = System.IO.File.ReadAllBytes(FileHelper.GetPathToSecretData());

            stego.SetSecretData(fileBytes);
            byte[] resultBytes = stego.SecretDataBytes;
            Assert.Equal(fileBytes, resultBytes);
        }
        public IActionResult Decrypt(string id, AlgorithmEnum algorithm)
        {
            var userImage = HttpContext.Session.Get <UserImage>(nameof(UserImage));
            var filePath  = Path.Combine(_stegoModel.GetUploadsPath(), id);

            if (System.IO.File.Exists(filePath) && (userImage.Guid == id || userImage.EmbededGuid == id))
            {
                using (var stego = new Stego(filePath))
                {
                    var result = stego.Decode(algorithm);
                    return(File(result, "application/octet-stream", "secret"));
                }
            }
            return(Content("Wrong id"));
        }
Beispiel #3
0
        public void Embed_Decode()
        {
            var image     = Image.Load(FileHelper.GetPathToImage());
            var fileBytes = System.IO.File.ReadAllBytes(FileHelper.GetPathToSecretData());

            byte[] resultBytes = null;
            using (var stego = new Stego(FileHelper.GetPathToImage()))
            {
                stego.SetSecretData(fileBytes);
                var imageWithSecret = stego.Embed(AlgorithmEnum.Lsb);
                stego.SetImage(imageWithSecret);
                resultBytes = stego.Decode(AlgorithmEnum.Lsb);
            }
            Assert.Equal(fileBytes, resultBytes);
        }
        public void Lsb_Encrypt_With_Key_Decrypt_Without_Key_Should_Throws_Error()
        {
            var fileBytes = System.IO.File.ReadAllBytes(FileHelper.GetPathToSecretData());

            using (var stego = new Stego(FileHelper.GetPathToImage()))
            {
                stego.SetSecretData(fileBytes);
                stego.SetSettings(new StegoCore.Model.Settings
                {
                    Key = "aaa"
                });
                var imageWithSecret = stego.Embed(AlgorithmEnum.Lsb);
                stego.SetImage(imageWithSecret);
                stego.SetSettings(null);

                DecodeException ex = Assert.Throws <DecodeException>(() => { stego.Decode(AlgorithmEnum.Lsb); });
            }
        }
        public void Lsb_Encrypt_With_Key_Decrypt_With_Key()
        {
            var fileBytes = System.IO.File.ReadAllBytes(FileHelper.GetPathToSecretData());

            using (var stego = new Stego(FileHelper.GetPathToImage()))
            {
                stego.SetSecretData(fileBytes);
                stego.SetSettings(new StegoCore.Model.Settings
                {
                    Key = "aaa"
                });
                var imageWithSecret = stego.Embed(AlgorithmEnum.Lsb);
                stego.SetImage(imageWithSecret);
                byte[] resultSecret = stego.Decode(AlgorithmEnum.Lsb);

                Assert.Equal(fileBytes, resultSecret);
            }
        }
Beispiel #6
0
        public async Task <EmbedResult> Embed(IFormFile secret, AlgorithmEnum algorithm, string format, ISession session)
        {
            var userImage   = session.Get <UserImage>(nameof(UserImage));
            var filePath    = Path.Combine(GetUploadsPath(), userImage.Guid);
            var embedResult = new EmbedResult
            {
                Algorithm = algorithm,
                Success   = false
            };

            if (secret != null && secret.Length > 0 && System.IO.File.Exists(filePath))
            {
                byte[] secretBytes = null;
                using (var memoryStrem = new MemoryStream())
                {
                    await secret.CopyToAsync(memoryStrem);

                    secretBytes = memoryStrem.ToArray();
                }
                using (var stego = new Stego(filePath))
                {
                    stego.SetSecretData(secretBytes);
                    var imageWithSecret = stego.Embed(algorithm);
                    var formatType      = Helpers.FormatHelper.GetEncoderByName(format);
                    if (formatType is SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder)
                    {
                        (formatType as SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder).Quality = 100;
                    }
                    imageWithSecret.Save(Path.Combine(GetUploadsPath(), embedResult.Guid), formatType);
                    embedResult.Success   = true;
                    embedResult.Format    = userImage.EmbededFormat = format;
                    userImage.EmbededGuid = embedResult.Guid;
                }
                session.Set <UserImage>(nameof(UserImage), userImage);
            }
            else
            {
                throw new InvalidDataException("You have to select secret file to embed in image");
            }
            return(embedResult);
        }