Go 只加密 16 字节消息长度的文本吗?
Is Go only encrypt text in a 16-byte message length?
我尝试在 Golang 中使用 AES 加密消息。
func main() {
key := "mysupersecretkey32bytecharacters"
plainText := "thisismyplaintextingolang"
fmt.Println("My Encryption")
byteCipherText := encrypt([]byte(key), []byte(plainText))
fmt.Println(byteCipherText)
}
func encrypt(key, plaintext []byte) []byte {
cphr, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
ciphertext := make([]byte, len(plaintext))
cphr.Encrypt(ciphertext, plaintext)
return ciphertext
}
那个函数 returns : [23 96 11 10 70 223 95 118 157 250 80 92 77 26 137 224 0 0 0 0 0 0 0 0 0]
在该结果中,只有 16 个非零字节值。这意味着 Go 中的 AES 加密只加密 16 个字符。
是否可以在 Go AES 中加密超过 16 个字符而不使用 AES 中的任何模式(如 GCM,CBC,CFB,..等),只是纯 AES?
这与go无关。 AES 是一种加密 16 字节块的块密码。要加密较长的消息,可以使用多种模式来实现此目的。
aes.NewCipher
returns cipher.Block
的一个实例,它以 16 字节的块进行加密(这就是纯 AES 的工作方式)。
mode of operation 从字面上确定长度超过 16 字节的消息如何加密。最简单的一种是 ECB(一种“no-op”模式),它使用相同的密钥简单地以 16 字节的块重复加密。您可以使用简单的 for-loop 执行相同的操作,但请记住 ECB 不是很安全。
我尝试在 Golang 中使用 AES 加密消息。
func main() {
key := "mysupersecretkey32bytecharacters"
plainText := "thisismyplaintextingolang"
fmt.Println("My Encryption")
byteCipherText := encrypt([]byte(key), []byte(plainText))
fmt.Println(byteCipherText)
}
func encrypt(key, plaintext []byte) []byte {
cphr, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
ciphertext := make([]byte, len(plaintext))
cphr.Encrypt(ciphertext, plaintext)
return ciphertext
}
那个函数 returns : [23 96 11 10 70 223 95 118 157 250 80 92 77 26 137 224 0 0 0 0 0 0 0 0 0]
在该结果中,只有 16 个非零字节值。这意味着 Go 中的 AES 加密只加密 16 个字符。 是否可以在 Go AES 中加密超过 16 个字符而不使用 AES 中的任何模式(如 GCM,CBC,CFB,..等),只是纯 AES?
这与go无关。 AES 是一种加密 16 字节块的块密码。要加密较长的消息,可以使用多种模式来实现此目的。
aes.NewCipher
returns cipher.Block
的一个实例,它以 16 字节的块进行加密(这就是纯 AES 的工作方式)。
mode of operation 从字面上确定长度超过 16 字节的消息如何加密。最简单的一种是 ECB(一种“no-op”模式),它使用相同的密钥简单地以 16 字节的块重复加密。您可以使用简单的 for-loop 执行相同的操作,但请记住 ECB 不是很安全。