golang AES 128解密
以下是使用Go语言进行AES 128解密的示例代码:
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
)
func main() {
key := []byte("0123456789abcdef") // AES密钥,16字节
ciphertext, _ := base64.StdEncoding.DecodeString("XqR8I9JqJvtDLrnOt9+1sg==") // 待解密的密文
iv := ciphertext[:aes.BlockSize] // 获取IV向量
block, err := aes.NewCipher(key) // 创建AES加密块
if err != nil {
panic(err)
}
mode := cipher.NewCBCDecrypter(block, iv) // 创建CBC解密器
plaintext := make([]byte, len(ciphertext)-aes.BlockSize) // 创建明文缓冲区
mode.CryptBlocks(plaintext, ciphertext[aes.BlockSize:]) // 解密密文
fmt.Printf("%s\n", plaintext)
}
请注意,此示例代码仅用于演示目的,实际使用中应该处理错误和异常情况
原文地址: https://www.cveoy.top/t/topic/emQu 著作权归作者所有。请勿转载和采集!