提交 402ab322 编写于 作者: A Anchor

Fix grammar and translations for 09.6.md [en]

上级 d0f1c187
# 9.6 Encrypt and decrypt data # 9.6 Encrypting and decrypting data
The previous section describes how to store passwords, but sometimes we want to change some sensitive data encrypted and stored up sometime in the future, with the need to decrypt them out , then we should use a symmetric encryption algorithm to meet our needs. The previous section describes how to securely store passwords, but sometimes it might be neccessary to modify some sensitive encrypted data that has already been stored into our database. When data decryption is required, we should use a symmetric encryption algorithm instead of the one-way hashing techniques we've previously covered.
## Base64 Encryption and decryption ## Base64 Encryption and decryption
If the Web application is simple enough, data security is no less stringent requirements, then you can use a relatively simple method of encryption and decryption is `base64`, this approach is relatively simple to implement , Go language `base64` package has been well support of this , consider the following examples: If the web application is relatively simple, and the data security requirements are not so stringent, then you can use a relatively simple method of encryption and decryption using `base64`. This approach is relatively straightforward to implement, and Go's `base64` package has good support for this. Consider the following example:
package main package main
...@@ -42,13 +42,12 @@ If the Web application is simple enough, data security is no less stringent requ ...@@ -42,13 +42,12 @@ If the Web application is simple enough, data security is no less stringent requ
## Advanced encryption and decryption ## Advanced encryption and decryption
Go inside the `crypto` language support symmetric encryption advanced encryption package are: The Go language supports symmetric encryption algorithms in its `crypto` package. Two advanced encryption modules are:
- `crypto/aes` package: AES (Advanced Encryption Standard), also known as Rijndael encryption method used is the U.S. federal government as a block encryption standard. - `crypto/aes` package: AES (Advanced Encryption Standard), also known as Rijndael encryption method, is used by the U.S. federal government as a block encryption standard.
- `crypto/des` package: DES (Data Encryption Standard), is a symmetric encryption standard , is currently the most widely used key system, especially in protecting the security of financial data. - `crypto/des` package: DES (Data Encryption Standard), is a symmetric encryption standard . It's currently the most widely used key system, especially in protecting the security of financial data. It used to be the United States federal government's encryption standard, but has now been replaced by AES.
Was a United States federal government encryption standard, but has now been replaced by AES.
Because of these two algorithms using methods similar to, so in this, we just aes package as an example to explain their use, see the following example Because using these two encryption algorithms is quite similar, we'll just use the `aes` package in the following example to demonstrate how you'd typically use these packages:
package main package main
...@@ -64,7 +63,7 @@ Because of these two algorithms using methods similar to, so in this, we just ae ...@@ -64,7 +63,7 @@ Because of these two algorithms using methods similar to, so in this, we just ae
func main() { func main() {
// Need to encrypt a string // Need to encrypt a string
plaintext := []byte("My name is Astaxie") plaintext := []byte("My name is Astaxie")
// If the incoming encrypted strings of words, plaint is that the incoming string // If there is an incoming string of words to be encrypted, set plaintext to that incoming string
if len(os.Args) > 1 { if len(os.Args) > 1 {
plaintext = []byte(os.Args[1]) plaintext = []byte(os.Args[1])
} }
...@@ -77,7 +76,7 @@ Because of these two algorithms using methods similar to, so in this, we just ae ...@@ -77,7 +76,7 @@ Because of these two algorithms using methods similar to, so in this, we just ae
fmt.Println(len(key_text)) fmt.Println(len(key_text))
// Create the encryption algorithm aes // Create the aes encryption algorithm
c, err := aes.NewCipher([]byte(key_text)) c, err := aes.NewCipher([]byte(key_text))
if err != nil { if err != nil {
fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err) fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)
...@@ -97,7 +96,7 @@ Because of these two algorithms using methods similar to, so in this, we just ae ...@@ -97,7 +96,7 @@ Because of these two algorithms using methods similar to, so in this, we just ae
fmt.Printf("%x=>%s\n", ciphertext, plaintextCopy) fmt.Printf("%x=>%s\n", ciphertext, plaintextCopy)
} }
Above by calling the function `aes.NewCipher` ( parameter key must be 16, 24 or 32 of the [] byte, respectively, corresponding to the AES-128, AES-192 or AES-256 algorithm ) , returns a `cipher.Block` Interface this interface implements three functions: Calling the above function `aes.NewCipher` (whose []byte key parameter must be 16, 24 or 32, corresponding to the AES-128, AES-192 or AES-256 algorithms, respectively), returns a `cipher.Block` Interface that implements three functions:
type Block interface { type Block interface {
// BlockSize returns the cipher's block size. // BlockSize returns the cipher's block size.
...@@ -112,11 +111,11 @@ Above by calling the function `aes.NewCipher` ( parameter key must be 16, 24 or ...@@ -112,11 +111,11 @@ Above by calling the function `aes.NewCipher` ( parameter key must be 16, 24 or
Decrypt(dst, src []byte) Decrypt(dst, src []byte)
} }
These three functions implement encryption and decryption operations, a detailed look at the operation of the above example . These three functions implement encryption and decryption operations; see the Go documentation for a more detailed explanation.
## Summary ## Summary
This section describes several encryption algorithms, when the development of Web applications can be used in different ways according to the demand for encryption and decryption , the general application of base64 algorithm can be used , then you can use more advanced or AES DES algorithm . This section describes several encryption algorithms which can be used in different ways according to your web application's encryption and decryption needs. For the most basic applications, base64 encoding may suffice. For applications with more stringent security requirements, it's recommended to use the more advanced AES or DES algorithm .
## Links ## Links
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册