Encrypt and decrypt data
Last updated
Was this helpful?
Last updated
Was this helpful?
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.
The Go language supports symmetric encryption algorithms in its crypto
package. Do not use anything except AES in if you don't know what you're doing!
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.
In the following example we demonstrate how to encrypt data using AES in GCM mode:
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:
These three functions implement encryption and decryption operations; see the Go documentation for a more detailed explanation.
This section describes encryption algorithms which can be used in different ways according to your web application's encryption and decryption needs. For applications with even basic security requirements it is recommended to use AES in GCM mode.
Previous:
Next: