请教如下的示例代码,没有 IV (初始化向量)
来源: https://www.developer.com/languages/cryptography-in-go/
上面文章提到的案例是:
~~~
package main
import (
"crypto/aes"
"encoding/hex"
"fmt"
)
func encryptMessage(key string, message string) string {
c, err := aes.NewCipher([]byte(key))
if err != nil {
fmt.Println(err)
}
msgByte := make([]byte, len(message))
c.Encrypt(msgByte, []byte(message))
return hex.EncodeToString(msgByte)
}
func decryptMessage(key string, message string) string {
txt, _ := hex.DecodeString(message)
c, err := aes.NewCipher([]byte(key))
if err != nil {
fmt.Println(err)
}
msgByte := make([]byte, len(txt))
c.Decrypt(msgByte, []byte(txt))
msg := string(msgByte[:])
return msg
}
func main() {
plainText := "This is a secret"
key := "this_must_be_of_32_byte_length!!"
emsg := encryptMessage(key, plainText)
dmesg := decryptMessage(key, emsg)
fmt.Println("Encrypted Message: ", emsg)
fmt.Println("Decrypted Message: ", dmesg)
}
~~~
请教下:aes 的默认的加密模式是什么? [比如 cbc 之类的加密模式是哪一种?] 没有 openSSL 里的那种初始化变量 IV ,是有个默认值?还是说 go 标准库里默认的初始化 iv=key ?
有疑问加站长微信联系(非本文作者)