So, you see, this method is a way to encrypt data so that it is safe and cannot be read by people who don't have the decryption key. Just imagine, friends, you have a diary that you lock with a padlock. Only people who have the key can open and read your diaries.
Symmetric encryption is like friends and friends, what's this, hahaha, the point is, it's like having the same key to open the lock. This key is used for encryption (locking) and decryption (unlocking) data. So, both friends and friends can lock and unlock the same data as long as you have the key.
The signature here is not a physical signature, but rather a digital signature. This signature ensures that the data sent is truly from friends and no one has changed the data midway. So, friends, you can be sure that the data you receive is genuine from the source and has not been tampered with.
Now let's see how to use this method in Golang.
package main import ( "crypto/aes" "crypto/cipher" "crypto/rand" "encoding/hex" "fmt" "io" ) func encrypt(key, text []byte) (string, error) { block, err := aes.NewCipher(key) if err != nil { return "", err } ciphertext := make([]byte, aes.BlockSize len(text)) iv := ciphertext[:aes.BlockSize] if _, err := io.ReadFull(rand.Reader, iv); err != nil { return "", err } stream := cipher.NewCFBEncrypter(block, iv) stream.XORKeyStream(ciphertext[aes.BlockSize:], text) return fmt.Sprintf("%x", ciphertext), nil } func decrypt(key []byte, cryptoText string) (string, error) { ciphertext, _ := hex.DecodeString(cryptoText) block, err := aes.NewCipher(key) if err != nil { return "", err } if len(ciphertext)Signature Golang
package main import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "fmt" ) func createHMAC(key, message []byte) string { mac := hmac.New(sha256.New, key) mac.Write(message) return hex.EncodeToString(mac.Sum(nil)) } func verifyHMAC(key, message []byte, signature string) bool { expectedMAC := createHMAC(key, message) return hmac.Equal([]byte(expectedMAC), []byte(signature)) } func main() { key := []byte("my-secret-key") message := []byte("important message") signature := createHMAC(key, message) fmt.Printf("Signature: %s\n", signature) isValid := verifyHMAC(key, message, signature) fmt.Printf("Is valid: %t\n", isValid) }So the Standard Symmetric Encryption Signature Method is important for maintaining the security and integrity of your data. With symmetric encryption, you can encrypt your data to make it safe, and with a signature, you can ensure that the data you receive or send is genuine and has not been tampered with. So, make sure friends use this method for all kinds of needs that require high security.
Source:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3