You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package utils
import ( "bytes" "crypto/cipher" "crypto/des" )
func padding(src []byte, blocksize int) []byte { n := len(src) padnum := blocksize - n%blocksize pad := bytes.Repeat([]byte{byte(padnum)}, padnum) dst := append(src, pad...) return dst }
func unpadding(src []byte) []byte { n := len(src) unpadnum := int(src[n-1]) dst := src[:n-unpadnum] return dst }
func EncryptDES(src []byte) []byte { key := []byte("qimiao66") block, _ := des.NewCipher(key) src = padding(src, block.BlockSize()) blockmode := cipher.NewCBCEncrypter(block, key) blockmode.CryptBlocks(src, src) return src }
func DecryptDES(src []byte) []byte { key := []byte("qimiao66") block, _ := des.NewCipher(key) blockmode := cipher.NewCBCDecrypter(block, key) blockmode.CryptBlocks(src, src) src = unpadding(src) return src
}
|