golang写一段 AES 256 ECB解密代码
下面是一段使用Go语言实现AES 256 ECB解密的代码示例:
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
)
func main() {
// 待解密的密文
ciphertext := "J8QeEw2NQx6iOOl5/wUqUQ=="
// Base64解码
ciphertextBytes, err := base64.StdEncoding.DecodeString(ciphertext)
if err != nil {
panic(err)
}
// 密钥
key := []byte("01234567890123456789012345678901")
// 创建AES解密器
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
// 解密
plaintext := make([]byte, len(ciphertextBytes))
ecb := cipher.NewECBDecrypter(block)
ecb.CryptBlocks(plaintext, ciphertextBytes)
// 输出解密结果
fmt.Println(string(plaintext))
}
注意:本代码示例仅用于学习和参考,实际应用时应当更加严格地处理错误和异常情况。另外,ECB模式不是安全的加密模式,建议使用更加安全的加密模式,如CBC、CFB、OFB等
原文地址: https://www.cveoy.top/t/topic/flOH 著作权归作者所有。请勿转载和采集!