Golang AES ECB加密

前端之家收集整理的这篇文章主要介绍了Golang AES ECB加密前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试在Go中模拟基本上是AES ECB模式加密的算法.

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

  1. func Decrypt(data []byte) []byte {
  2. cipher,err := aes.NewCipher([]byte(KEY))
  3. if err == nil {
  4. cipher.Decrypt(data,PKCS5Pad(data))
  5. return data
  6. }
  7. return nil
  8. }

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

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

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

  1. func AESECB(ciphertext []byte) []byte {
  2. cipher,_ := aes.NewCipher([]byte(KEY))
  3. fmt.Println("AESing the data")
  4. bs := 16
  5. if len(ciphertext)%bs != 0 {
  6. panic("Need a multiple of the blocksize")
  7. }
  8.  
  9. plaintext := make([]byte,len(ciphertext))
  10. for len(plaintext) > 0 {
  11. cipher.Decrypt(plaintext,ciphertext)
  12. plaintext = plaintext[bs:]
  13. ciphertext = ciphertext[bs:]
  14. }
  15. return plaintext
  16. }

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

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

猜你在找的Go相关文章