小编Yur*_*ury的帖子

三重DES解密在再次解密时返回错误的前16个字节

当我尝试再次解密相同的字节切片时,我遇到了解密问题.

澄清代码示例:

package main

import (
    "fmt"
    "crypto/cipher"
    "crypto/des"
)

const (
    // tripleKey is TripleDES key string (3x8 bytes)
    tripleKey = "12345678asdfghjkzxcvbnmq"
)

var (
    encrypter cipher.BlockMode
    decrypter cipher.BlockMode
)

func init() {
    // tripleDESChiper is chiper block based on tripleKey used for encryption/decryption
    tripleDESChiper, err := des.NewTripleDESCipher([]byte(tripleKey))
    if err != nil {
        panic(err)
    }

    // iv is Initialization Vector used for encrypter/decrypter creation
    ciphertext := []byte("0123456789qwerty")
    iv := ciphertext[:des.BlockSize]

    // create encrypter and decrypter
    encrypter = cipher.NewCBCEncrypter(tripleDESChiper, iv) …
Run Code Online (Sandbox Code Playgroud)

encryption go tripledes

2
推荐指数
1
解决办法
454
查看次数

标签 统计

encryption ×1

go ×1

tripledes ×1