package utils import ( "crypto/cipher" "crypto/des" ) //des加密 func CBCDesEncrypt(key, iv, plainText []byte) ([]byte, error) { block, err := des.NewCipher(key) if err != nil { return nil, err } blockSize := block.BlockSize() origData := pkcs5Padding(plainText, blockSize) blockMode := cipher.NewCBCEncrypter(block, iv) cryted := make([]byte, len(origData)) blockMode.CryptBlocks(cryted, origData) return cryted, nil } //des解密 func CBCDesDecrypt(key, iv, cipherText []byte) ([]byte, error) { block, err := des.NewCipher(key) if err != nil { return nil, err } blockMode := cipher.NewCBCDecrypter(block, iv) origData := make([]byte, len(cipherText)) blockMode.CryptBlocks(origData, cipherText) origData = pkcs5UnPadding(origData) return origData, nil }