以下是golang中使用AES-256 CBC模式解密的代码,其中IV为{ 16, 25, 78, 56, 21, 89, 62, 10, 65, 15, 89, 35, 24, 25, 86 }:

package main

import (
	"crypto/aes"
	"crypto/cipher"
	"encoding/base64"
	"fmt"
)

func main() {
	key := []byte("0123456789abcdef0123456789abcdef")
	iv := []byte{16, 25, 78, 56, 21, 89, 62, 10, 65, 15, 89, 35, 24, 25, 86}
	ciphertext, _ := base64.StdEncoding.DecodeString("oNqmh7LzhrXJZrZo3UTiVw==")

	block, err := aes.NewCipher(key)
	if err != nil {
		panic(err)
	}

	mode := cipher.NewCBCDecrypter(block, iv)

	plaintext := make([]byte, len(ciphertext))
	mode.CryptBlocks(plaintext, ciphertext)

	fmt.Printf("%s\n", plaintext)
}

在这个示例代码中,我们使用了一个256位的AES密钥和一个长度为15的IV。密文使用Base64编码,并使用crypto/cipher包中的NewCBCDecrypter方法来解密。最后,我们将解密的明文输出到控制台。

注意:在实际使用中,请勿硬编码密钥和IV,应该使用安全的密钥管理和随机生成的IV

golang写一段 AES-256 CBC 解密代码 IV为 16 25 78 56 21 89 62 10 65 15 89 35 24 25 86

原文地址: https://www.cveoy.top/t/topic/flPv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录