以下是使用golang实现的DES加密示例,不含斜杠:

package main

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

func main() {
    key := []byte("12345678") // 8字节的密钥
    plaintext := []byte("hello world") // 待加密的明文

    block, err := des.NewCipher(key)
    if err != nil {
        panic(err)
    }

    // 使用CBC模式加密
    iv := []byte("12345678") // 8字节的初始向量
    mode := cipher.NewCBCEncrypter(block, iv)
    ciphertext := make([]byte, len(plaintext))
    mode.CryptBlocks(ciphertext, plaintext)

    // 对加密后的密文进行Base64编码
    encoded := base64.StdEncoding.EncodeToString(ciphertext)
    fmt.Println(encoded)
}

注意,这里使用的是DES加密算法,已经被认为是不安全的,建议使用更安全的加密算法,如AES。


原文地址: https://www.cveoy.top/t/topic/tFf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录