bmp图像 转图像数据_如何隐藏图像中的数据

bmp图像 转图像数据

This is the purpose of steganography.

这就是隐写术的目的。

什么是隐写术? (What’s Steganography?)

Steganography is the art and science of embedding and hiding information within a medium in plain sight. It’s related to cryptography and is just about as old. For example, it was used by the Ancient Greeks to hide information about troop movements by tattooing the information on someone’s head and then letting the person grow out their hair.

隐写术是一门在视觉上将信息嵌入和隐藏在媒体中的艺术和科学。 它与密码学有关,与它差不多古老。 例如, 古希腊人使用它通过在某人的头上纹身该信息然后让该人长出头发来隐藏有关部队运动的信息。

The word steganography comes from the New Latin steganographia, which combines the Greek words steganós, meaning “covered or concealed,” and -graphia meaning “writing.”

隐写术一词来自新拉丁语隐写术 ,它结合了希腊语steganós(意为“被遮盖或隐藏”)和-graphia(意为“书写”)。

In the context of computer science, the medium is an ordinary file, usually an image. The secret data can then be extracted at its destination later.

在计算机科学的上下文中,介质是普通文件,通常是映像。 然后可以在目的地将秘密数据提取出来。

为什么要进行隐写术? (Why Steganography?)

Unlike conventional encryption, where it’s obvious that a message is being hidden, the purpose of steganography is to hide a message in plain sight without anyone noticing.

与传统的加密(很明显,消息被隐藏)不同,隐秘术的目的是在不引起任何人注意的情况下将消息隐藏在可见的地方。

The uses of steganography are as varied as the uses of communication itself. It can be useful in situations where sending encrypted messages might raise suspicion, such as in countries where free speech is suppressed. It’s also frequently used as a digital watermark to find when images or audio files are stolen. And also, for fun.

隐写术的用途与通信本身的用途一样多变。 在发送加密邮件可能引起怀疑的情况下(例如在禁止言论自由的国家中),此功能很有用。 它还经常用作数字水印,以查找图像或音频文件何时被盗。 而且,很有趣。

Since there’s probably tons of images on your computer, why not use them to hide data without affecting the images and arising suspicion?

由于您的计算机上可能有大量的图像,为什么不使用它们隐藏数据而不影响图像并引起怀疑?

隐写术如何实施? (How’s Steganography Implemented?)

All steganography requires is a covertext, which is the medium where data will be hidden, a message that’s made up of data, an algorithm that decides how to hide and retrieve the data, and, optionally, a key that’ll be used to randomize the placement of the data and, perhaps, even encrypt it.

所有的隐写术都需要一个Covertext ,这是隐藏数据的媒介,一条由数据组成的消息 ,一种决定如何隐藏和检索数据的算法以及(可选)用于随机化的密钥数据的放置,甚至加密。

There are several different techniques for concealing data inside of normal files. The most commonly discussed steganography is embedded images. This is also the form that has the most research investigating it. While there are many types of algorithms, the three most common are the LSB, DCT, and append types.

在普通文件中隐藏数据有几种不同的技术。 最常讨论的隐写术是嵌入式图像。 这也是研究最多的表格。 尽管算法类型很多,但最常见的三种是LSBDCTappend类型

LSB, which stands for least significant bit, is the most widely used. This technique changes the last few bits in a byte to encode a message, which is especially useful in something like an image, where the red, green, and blue values of each pixel are represented by eight bits (one byte) ranging from 0 to 255 in decimal or 00000000 to 11111111 in binary.

LSB代表最低有效位,是使用最广泛的。 此技术更改字节中的最后几位以对消息进行编码,这在诸如图像之类的东西中尤其有用,在该图像中,每个像素的红色,绿色和蓝色值由从0到0的八位(一个字节)表示。十进制为255或二进制为00000000到11111111。

Image for post
Wikimedia Commons. Wikimedia Commons

Changing the last two bits in a completely red pixel from 11111111 to 11111101 only changes the red value from 255 to 253, which, to the naked eye, creates a nearly imperceptible change in color but still allows us to encode data inside of the picture.

将全红色像素的最后两位从11111111更改为11111101,只会将红色值从255更改为253,用肉眼可以看到几乎不可见的颜色变化,但仍允许我们对图片内部的数据进行编码。

Image for post
Technical Foundation 技术基础

The LSB technique works well for media files, where slightly changing byte values creates only slight imperceptible changes, but things like ASCII text don’t fair so well, where a single bit out of place will completely change the character.

LSB技术适用于媒体文件,其中字节值略有变化只会产生轻微的察觉不到的更改,但是像ASCII文本之类的东西就不太合适,因为一点点的位置会完全改变字符。

Also, because it has an effect on the amount of a color, even if pretty small, replacing this bit with a bit from the hidden data will have the smallest effect on the picture possible. The more bits replaced, the more bit depth is available, and the larger the image, the more data that can be stored in the photo. However, the more bits that are replaced, the more obvious the alterations will appear to both a statistical inspection and a visual inspection.

同样,由于它会影响颜色量,即使很小,用隐藏数据中的一位替换该位对图片的影响也可能最小。 替换的位数越多,可用的位数越 ,图像越大,照片中可以存储的数据越多。 但是,替换的位数越多,对于统计检查和外观检查而言 ,更改的表现就越明显。

For this reason, there are lots of other steganography techniques, each with their own benefits and drawbacks.

因此,还有许多其他隐写术技术,每种都有各自的优缺点。

Another far less detectable one is called the discrete cosine transform (DCT) coefficient technique, which slightly changes the weights (coefficients) of the cosine waves that are used to reconstruct a JPEG image. It works by calculating the frequencies of the image and then replacing some of them. DCT algorithms are more subtle in the way they manipulate photos and so are harder to detect. Note that larger transformations (due to more embedded data) will make the manipulations more obvious.

另一种难以检测的技术称为离散余弦变换(DCT)系数技术 ,该技术会稍微改变用于重建JPEG图像的余弦波的权重(系数)。 它通过计算图像的频率然后替换其中一些来工作。 DCT算法处理照片的方式更加微妙,因此难以检测。 请注意,较大的转换(由于嵌入的数据更多)将使操作更加明显。

Just about the worst of these algorithms is the class of append algorithms. Rather than hide the data in the photo by manipulating the picture, it instead appends the data to the end of the file as padding. In this manner, the data is hidden and never read by any photo-displaying program. The only advantage of these algorithms are the simplicity of programming the algorithm and the fact that they’re immune to visual inspection of the picture.

这些算法中最差的就是追加算法的类别。 它不是通过操纵图片来隐藏照片中的数据,而是将数据作为填充追加到文件的末尾。 以这种方式,数据被隐藏并且从不被任何照片显示程序读取。 这些算法的唯一优点是算法编程的简单性以及它们不受图像视觉检查的影响。

有效地使用隐写术 (Using Steganography Effectively)

By default, steganography is a type of security through obscurity, since it only hides the data — without encryption. Encrypting data before embedding it adds an extra layer of security.

默认情况下,隐秘术是一种通过隐蔽性实现的安全性,因为它仅隐藏数据而没有加密。 嵌入数据之前对其进行加密会增加一层安全性。

That's the main goal of Cryptosteganography, a Python steganography module to store messages — or other files protected with encryption — inside an image.

这是Cryptosteganography的主要目标, Cryptosteganography是一个Python隐写模块,用于将消息(或其他受加密保护的文件)存储在图像内。

This module enhance the security of the steganography through data encryption. The data concealed is encrypted using AES-256 encryption, a popular algorithm used in symmetric-key cryptography. AES has been adopted by the U.S. government and is now used worldwide.

该模块通过数据加密来增强隐写技术的安全性。 隐藏的数据使用AES -256加密(对称密钥加密中使用的一种流行算法)进行加密。 AES已被美国政府采用,现已在全球范围内使用。

A brute-force breakthrough of the AES-256, which has a key length of 256 bits, requires 2,128 times more computational power than a 128-bit key. Fifty supercomputers that could check a billion billion (10^18) AES keys per second (if such a device could ever be made) would, in theory, require about 3×1051 years to exhaust the 256-bit key space.

AES-256的强行突破(密钥长度为256位)比128位密钥需要2128倍的计算能力。 从理论上讲,五十台超级计算机每秒可检查10亿个(10 ^ 18)AES密钥(如果可以制造这样的设备),理论上将需要3×1051年的时间来耗尽256位密钥空间。

The following table shows that possible key combinations exponentially increase with the key size.

下表显示了可能的按键组合随按键大小呈指数增加。

Image for post
EE Times. EE Times

将隐藏的数据嵌入到图像中 (Embed Hidden Data Into an Image)

Using Cryptosteganography is very easy. The module can be used as a library inside a Python program or as shell command-line program.

使用密码隐写术非常容易。 该模块可用作Python程序内部的库或Shell命令行程序。

You need to have pip installed, the Python Package Installer, which can be done following these instructions. Note that on most modern Linux systems, Python and pip come installed with the OS by default.

您需要安装pip Python Package Installer,可以按照以下说明进行操作 。 请注意,在大多数现代Linux系统上,默认情况下,Python和pip随操作系统一起安装。

After this, run the command below to install Cryptosteganography from the terminal:

之后,运行以下命令从终端安装Cryptosteganography

pip3 install cryptosteganography

Once it’s installed, you can check how to use it by passing the -h or — help argument.

安装完成后,您可以通过传递-h— help参数来检查如何使用它。

$ cryptosteganography -h
usage: cryptosteganography [-h] {save,retrieve} ...
A python steganography script that save/retrieve a text/file (AES 256
encrypted) inside an image.
positional arguments:
{save,retrieve} sub-command help
save save help
retrieve retrieve help
optional arguments:
-h, --help show this help message and exitThe arguments are broken down as follows:

For example, in order to embed data in an image, type the command below.

例如,为了将数据嵌入图像中,请键入以下命令。

$ cryptosteganography save -i vin-and-orion.png -m "My secret message..." -o output.png
Enter the key password:

After you enter the password, which will be used to generate the encryption key, the steganographic image is generated.

输入用于生成加密密钥的密码后,将生成密写图像。

To retrieve the hidden data from the steganographic image, you can run …

要从密写图像中检索隐藏的数据,可以运行…

$ cryptosteganography retrieve -i output.png
Enter the key password:
My secret message...

… and type the same password.

…,然后输入相同的密码。

The library also allows you to store other files inside the images, with the restriction that the file size must be smaller than the original image. You can check out more CLI options and how to use it as a library inside another Python program here.

该库还允许您将其他文件存储在图像内部,但限制是文件大小必须小于原始图像。 您可以在此处查看更多CLI选项以及如何将其用作另一个Python程序中的库。

Image for post
Side-by-side comparison of the original image and the steganographic image
原始图像和隐写图像的并排比较

好奇心 (A Note of Curiosity)

A few years ago, when I released this Python library, I proposed a small puzzle to my coworkers and study groups. The initial clues were spread out in the library’s source-code repository, in the image of my profile on GitHub, and on my personal website.

几年前,当我发布此Python库时,我向我的同事和研究小组提出了一个小难题。 最初的线索分布在图书馆的源代码存储库中, 我在GitHub上的个人 资料图片以及我的个人网站上

The puzzle remains unsolved.

难题仍未解决。

Note: Services like GitHub and others usually compress and/or transcode the original image after the user uploads, which can make hidden information corrupt and unrecoverable. In this particular example, I discovered if you upload an image with the exact size and encoding standard that GitHub uses for the original image (the image served without any URL query arguments like s, u, and v), the system will save the image as is, without making any changes. That’s why this image in the puzzle still has the information encrypted.

注意 :GitHub等服务通常会在用户上传后压缩和/或转码原始图像,这可能会使隐藏的信息损坏并且无法恢复。 在这个特定的示例中,我发现如果您上传的图像具有GitHub用于原始图像的确切大小和编码标准(图像提供时没有任何suv等URL查询参数),系统将保存该图像照原样进行,无需进行任何更改。 这就是为什么拼图中的该图像仍将信息加密的原因。

翻译自: https://medium.com/better-programming/hide-data-within-an-image-507f571aab89

bmp图像 转图像数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值