ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# package des `import "crypto/des"` des包实现了DES标准和TDEA算法,参见U.S. Federal Information Processing Standards Publication 46-3。 ## Index * [Constants](#pkg-constants) * [type KeySizeError](#KeySizeError) * [func (k KeySizeError) Error() string](#KeySizeError.Error) * [func NewCipher(key []byte) (cipher.Block, error)](#NewCipher) * [func NewTripleDESCipher(key []byte) (cipher.Block, error)](#NewTripleDESCipher) ## Constants ``` const BlockSize = 8 ``` DES字节块的大小。 ## type [KeySizeError](https://github.com/golang/go/blob/master/src/crypto/des/cipher.go#L15 "View Source") ``` type KeySizeError int ``` ### func (KeySizeError) [Error](https://github.com/golang/go/blob/master/src/crypto/des/cipher.go#L17 "View Source") ``` func (k KeySizeError) Error() string ``` ## func [NewCipher](https://github.com/golang/go/blob/master/src/crypto/des/cipher.go#L27 "View Source") ``` func NewCipher(key []byte) (cipher.Block, error) ``` 创建并返回一个使用DES算法的cipher.Block接口。 ## func [NewTripleDESCipher](https://github.com/golang/go/blob/master/src/crypto/des/cipher.go#L49 "View Source") ``` func NewTripleDESCipher(key []byte) (cipher.Block, error) ``` 创建并返回一个使用TDEA算法的cipher.Block接口。 Example ``` // NewTripleDESCipher can also be used when EDE2 is required by // duplicating the first 8 bytes of the 16-byte key. ede2Key := []byte("example key 1234") var tripleDESKey []byte tripleDESKey = append(tripleDESKey, ede2Key[:16]...) tripleDESKey = append(tripleDESKey, ede2Key[:8]...) _, err := des.NewTripleDESCipher(tripleDESKey) if err != nil { panic(err) } // See crypto/cipher for how to use a cipher.Block for encryption and // decryption. ```