golang 加密文件
Cryptography is mandatory in the current modern world. In this era of big data and data science, it is important to make sure your data is protected from a malicious attack.
在当前现代世界中,密码术是必不可少的。 在当今大数据和数据科学时代,确保保护您的数据免受恶意攻击非常重要。
There are many algorithms and techniques to ensure that your system is secure and no unauthorized access will be done to your data.
有许多算法和技术可以确保您的系统安全,并且不会对数据进行未经授权的访问。
Symmetric encryption is one of these techniques, and in this tutorial, I will show you how to do it in Go.
对称加密是这些技术之一,在本教程中,我将向您展示如何在Go中进行加密。
Note: The version of Go used in this tutorial is 1.14.7.
注意:本教程中使用的Go版本是1.14.7。
介绍 (Introduction)
The symmetric-key encryption is a technique used to encrypt a message where there is only one secret key. This key is used on both parts of the process, that is, to encrypt and decrypt the message.
对称密钥加密是一种用于加密只有一个秘密密钥的消息的技术。 该密钥在过程的两个部分都使用,即加密和解密消息。
![Image for post](https://miro.medium.com/max/9999/1*QPDIi-w9u5D9dRSwG-C6Dg.png)
Using any kind of symmetric-key algorithm, a message is converted into a form that cannot be understood. Unless someone has the secret key. In this case, both the sender and the receiver have the same key (exchanged in some secure way) so they can send messages and understand each other.
使用任何一种对称密钥算法,都会将消息转换为无法理解的形式。 除非有人拥有密钥。 在这种情况下,发送方和接收方都具有相同的密钥(以某种安全方式进行了交换),因此它们可以发送消息并相互理解。
The algorithm used determines the size of the key and the mode that the process of encryption or decryption is done. And, usually, longer the key, harder is to hack it and more secure is your encryption. For example, a 128-bits key can take up to billions of years to be broken by a normal computer.
所使用的算法确定密钥的大小以及完成加密或解密过程的方式。 而且,通常,密钥越长,破解就越困难,而加密则更加安全。 例如,一个128位的密钥可能需要数十亿年才能被普通计算机破解。
There are two types of algorithms:
有两种算法: