package des

import "crypto/des"

des包实现了DES标准和TDEA算法,参见U.S. Federal Information Processing Standards Publication 46-3。

Index

Constants

const BlockSize = 8

DES字节块的大小。

type KeySizeError

type KeySizeError int

func (KeySizeError) Error

func (k KeySizeError) Error() string

func NewCipher

func NewCipher(key []byte) (cipher.Block, error)

创建并返回一个使用DES算法的cipher.Block接口。

func NewTripleDESCipher

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.