DES加密 CBC模式
(origData, key []byte)
| 9 | |
| 10 | //DES加密 CBC模式 |
| 11 | func DesEncrypt(origData, key []byte) ([]byte, error) { |
| 12 | block, err := des.NewCipher(key) |
| 13 | if err != nil { |
| 14 | return nil, err |
| 15 | } |
| 16 | origData = PKCS5Padding(origData, block.BlockSize()) |
| 17 | blockMode := cipher.NewCBCEncrypter(block, key) |
| 18 | crypted := make([]byte, len(origData)) |
| 19 | blockMode.CryptBlocks(crypted, origData) |
| 20 | return crypted, nil |
| 21 | } |
| 22 | |
| 23 | func PKCS5Padding(cipherText []byte, blockSize int) []byte { |
| 24 | padding := blockSize - len(cipherText)%blockSize |
no test coverage detected