CFB解密问题:Go和JSON解组

I am having some trouble decrypting a string correctly. The first few bytes are not correct, the remaining characters are correct.

Encryption:

    user := User{username, password, *rsakey, username_maca, password_maca}

    u, _ := json.Marshal(user)
    ciphertext := make([]byte, userlib.BlockSize+len(u))

    iv := ciphertext[:userlib.BlockSize]
    copy(iv, userlib.RandomBytes(userlib.BlockSize))
    cipher := userlib.CFBEncrypter(password_byte, iv)
    cipher.XORKeyStream(ciphertext[userlib.BlockSize:], []byte(u))

Decryption:

    encryptd_data, valid := userlib.DatastoreGet(string(username_mac))

    iv := encryptd_data[:userlib.BlockSize]
    ciphertext := encryptd_data[userlib.BlockSize:]

    cipher := userlib.CFBDecrypter(password_byte, iv)
    cipher.XORKeyStream(ciphertext[userlib.BlockSize:], ciphertext[userlib.BlockSize:])

    var g uuid.UUID
    json.Unmarshal(ciphertext[userlib.BlockSize:], &g)

After decryption, the first few bytes are not correct and after unmarshalling, output is all zeros.

dongtong1226
dongtong1226 不要忽略错误;特别是json.Marshal和json.Unmarshal的返回。
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐