douju1968 2017-10-14 13:29
浏览 39

去河豚怪异的东西

I have the following function which encodes the string using Blowfish.If I put just a string to byte array it works. The problem is with line cipher.Encrypt(enc[0:],src)

func BlowFish(str string){
    key := []byte("super secret key")

    cipher,err := blowfish.NewCipher(key)
    if err != nil {
        log.Fatal(err)
    }


    //very weird that I get index out of range if I insert a var
    src :=[]byte(str+"


")

    var enc [512]byte
    cipher.Encrypt(enc[0:],src)

    fmt.Println("Encoded",enc)

    var decrypt[8] byte
    cipher.Decrypt(decrypt[0:],enc[0:])

    result:=bytes.NewBuffer(nil)
    result.Write(decrypt[0:8])

    fmt.Println(string(result.Bytes()))
}

I don't understand the problem

  • 写回答

2条回答 默认 最新

  • dongzong5017 2017-10-14 14:32
    关注

    Looks like I found what's wrong. cypher.Encrypt accepts byte array of length 8. But the length of byte array []byte(str+" ") is 4. That's why I get an index out of range. If I have an array []byte("My str to encode"+" "). It's len is len of 2 strings. The solution for now is to add more chars to have the length of array str+" .... " >=than 8

    评论

报告相同问题?

悬赏问题

  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿