Golang AES ECB加密

尝试在Go中模拟基本上是AES ECB模式加密的算法.

这是我到目前为止所拥有的

func Decrypt(data []byte) []byte {
    cipher,err := aes.NewCipher([]byte(KEY))
    if err == nil {
        cipher.Decrypt(data,PKCS5Pad(data))
        return data
    }
    return nil
}

我还有一个PKCS5Padding算法,经过测试和工作,它首先填充数据.我无法找到有关如何在Go AES包中切换加密模式的任何信息(绝对不是在the docs中).

我有这个代码用另一种语言,这就是我知道这个算法不能正常工作的方式.

编辑:这是我在问题页面上解释的方法

func AESECB(ciphertext []byte) []byte {
    cipher,_ := aes.NewCipher([]byte(KEY))
    fmt.Println("AESing the data")
    bs := 16
    if len(ciphertext)%bs != 0     {
        panic("Need a multiple of the blocksize")
    }

    plaintext := make([]byte,len(ciphertext))
    for len(plaintext) > 0 {
        cipher.Decrypt(plaintext,ciphertext)
        plaintext = plaintext[bs:]
        ciphertext = ciphertext[bs:]
    }
    return plaintext
}

这实际上并没有返回任何数据,也许我在将其从编写脚本转换为decripting时搞砸了

欧洲央行故意被排除在外,因为它不安全,请查看 issue 5597.

相关文章

什么是Go的接口? 接口可以说是一种类型,可以粗略的理解为他...
1、Golang指针 在介绍Golang指针隐式间接引用前,先简单说下...
1、概述 1.1 Protocol buffers定义 Protocol buffe...
判断文件是否存在,需要用到"os"包中的两个函数: os.Stat(...
1、编译环境 OS :Loongnix-Server Linux release 8.3 CPU指...
1、概述 Golang是一种强类型语言,虽然在代码中经常看到i:=1...