import "crypto"
crypto包搜集了常用的密码(算法)常量。
type PublicKey
type PrivateKey
type Hash
func (h Hash) Available() bool
func (h Hash) Size() int
func (h Hash) New() hash.Hash
func RegisterHash(h Hash, f func() hash.Hash)
type PublicKey interface{}
代表一个使用未指定算法的公钥。
type PrivateKey interface{}
代表一个使用未指定算法的私钥。
type Hash uint
Hash用来识别/标识另一个包里实现的加密函数。
const (
MD4 Hash = 1 + iota // 导入code.google.com/p/go.crypto/md4
MD5 // 导入crypto/md5
SHA1 // 导入crypto/sha1
SHA224 // 导入crypto/sha256
SHA256 // 导入crypto/sha256
SHA384 // 导入crypto/sha512
SHA512 // 导入crypto/sha512
MD5SHA1 // 未实现;MD5+SHA1用于TLS RSA
RIPEMD160 // 导入code.google.com/p/go.crypto/ripemd160
)
func (h Hash) Available() bool
报告是否有hash函数注册到该标识值。
func (h Hash) Size() int
返回给定hash函数返回值的字节长度。
func (Hash) New
func (h Hash) New() hash.Hash
创建一个使用给定hash函数的hash.Hash接口,如果该标识值未注册hash函数,将会panic。
func RegisterHash(h Hash, f func() hash.Hash)
import "crypto/aes"
aes包实现了AES加密算法,参见U.S. Federal Information Processing Standards Publication 197。
Constants
type KeySizeError
func (k KeySizeError) Error() string
func NewCipher(key []byte) (cipher.Block, error)
const BlockSize = 16
AES字节块大小。
type KeySizeError int
func (k KeySizeError) Error() string
func NewCipher(key []byte) (cipher.Block, error)
创建一个cipher.Block接口。参数key为密钥,长度只能是16、24、32字节,用以选择AES-128、AES-192、AES-256。
参考资料:
Go语言中文文档
http://www.golang.ltd/
Go语言官方文档
https://golang.google.cn/