go实现DES+CBC
DES
密钥长度:8
字节
CBC
分组长度要与算法密钥长度相同
//加密
func desCBCEncrypt(plainText []byte, key []byte) ([]byte, error) {
//TODO
//创建des接口
block, err := des.NewCipher(key)
if err != nil {
return nil ,err
}
//创建cbc分组
iv := bytes.Repeat([]byte("1"), block.BlockSize())
mode := cipher.NewCBCEncrypter(block, iv)
//填充
plainText, err = padding(plainText, block.BlockSize())
if err != nil {
return nil ,err
}
//加密
mode.CryptBlocks(plainText /*密文*/, plainText/*明文*/)
return plainText, nil
}
//解密
func desCBCDecrypt(encryptData []byte, key []byte) ([]byte, error) {
//创建des接口
block, err := des.NewCipher(key)
if err != nil {
return nil ,err
}
//创建cbc分组
iv := bytes.Repeat([]byte("1"), block.BlockSize())
mode := cipher.NewCBCDecrypter(block, iv)
//解密
mode.CryptBlocks(encryptData /*密文*