Package crypto

import "crypto"

Overview ▾


func RegisterHash

func RegisterHash(h Hash, f func() hash.Hash)

RegisterHash注册一个函数,该函数返回给定哈希函数的新实例. 旨在从实现散列函数的程序包中的init函数中调用它.

type Decrypter 1.5

解密器是不透明私钥的接口,可用于非对称解密操作. 一个示例是保存在硬件模块中的RSA密钥.

type Decrypter interface {
    // Public returns the public key corresponding to the opaque,
    // private key.
    Public() PublicKey

    // Decrypt decrypts msg. The opts argument should be appropriate for
    // the primitive used. See the documentation in each implementation for
    // details.
    Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error)

type DecrypterOpts 1.5

type DecrypterOpts interface{}

type Hash


type Hash uint
const (
    MD4         Hash = 1 + iota // import
    MD5                         // import crypto/md5
    SHA1                        // import crypto/sha1
    SHA224                      // import crypto/sha256
    SHA256                      // import crypto/sha256
    SHA384                      // import crypto/sha512
    SHA512                      // import crypto/sha512
    MD5SHA1                     // no implementation; MD5+SHA1 used for TLS RSA
    RIPEMD160                   // import
    SHA3_224                    // import
    SHA3_256                    // import
    SHA3_384                    // import
    SHA3_512                    // import
    SHA512_224                  // import crypto/sha512
    SHA512_256                  // import crypto/sha512
    BLAKE2s_256                 // import
    BLAKE2b_256                 // import
    BLAKE2b_384                 // import
    BLAKE2b_512                 // import


func (Hash) Available

func (h Hash) Available() bool


func (Hash) HashFunc 1.4

func (h Hash) HashFunc() Hash


func (Hash) New

func (h Hash) New() hash.Hash

New返回一个新的hash.Hash计算给定的hash函数. 如果哈希函数未链接到二进制文件中,则会引起新的恐慌.

func (Hash) Size

func (h Hash) Size() int

Size返回由给定哈希函数得出的摘要的长度(以字节为单位). 不需要将相关的哈希函数链接到程序中.

type PrivateKey


type PrivateKey interface{}

type PublicKey 1.2


type PublicKey interface{}

type Signer 1.4

签名者是不透明私钥的接口,可用于签名操作. 例如,保存在硬件模块中的RSA密钥.

type Signer interface {
    // Public returns the public key corresponding to the opaque,
    // private key.
    Public() PublicKey

    // Sign signs digest with the private key, possibly using entropy from
    // rand. For an RSA key, the resulting signature should be either a
    // PKCS#1 v1.5 or PSS signature (as indicated by opts). For an (EC)DSA
    // key, it should be a DER-serialised, ASN.1 signature structure.
    // Hash implements the SignerOpts interface and, in most cases, one can
    // simply pass in the hash function used as opts. Sign may also attempt
    // to type assert opts to other types in order to obtain algorithm
    // specific values. See the documentation in each package for details.
    // Note that when a signature of a hash of a larger message is needed,
    // the caller is responsible for hashing the larger message and passing
    // the hash (as digest) and the hash function (as opts) to Sign.
    Sign(rand io.Reader, digest []byte, opts SignerOpts) (signature []byte, err error)

type SignerOpts 1.4


type SignerOpts interface {
    // HashFunc returns an identifier for the hash function used to produce
    // the message passed to Signer.Sign, or else zero to indicate that no
    // hashing was done.
    HashFunc() Hash


Name Synopsis
aes 软件包aes实施AES加密(以前称为Rijndael),如美国联邦信息处理标准出版物197中所定义.
cipher 包密码实现标准的分组密码模式,可以将其包装在低级分组密码实现中.
des 软件包des实现了美国联邦信息处理标准出版物46-3中定义的数据加密标准(DES)和三重数据加密算法(TDEA).
dsa 软件包dsa实现了FIPS 186-3中定义的数字签名算法.
ecdsa 软件包ecdsa实现了FIPS 186-3中定义的椭圆曲线数字签名算法.
ed25519 软件包ed25519实现了Ed25519签名算法.
elliptic 包椭圆实现素数场上的多个标准椭圆曲线.
hmac 软件包hmac实现了美国联邦信息处理标准出版物198中定义的密钥哈希消息认证代码(HMAC).
md5 包md5实现了RFC 1321中定义的MD5哈希算法.
rand Package rand实现了加密安全的随机数生成器.
rc4 包rc4实现了RC4加密,如Bruce Schneier的Applied Cryptography中所定义.
rsa 软件包rsa实施PKCS#1中指定的RSA加密.
sha1 软件包sha1实现了RFC 3174中定义的SHA-1哈希算法.
sha256 软件包sha256实现了FIPS 180-4中定义的SHA224和SHA256哈希算法.
sha512 软件包sha512实现了FIPS 180-4中定义的SHA-384,SHA-512,SHA-512 / 224和SHA-512 / 256哈希算法.
subtle 软件包的细微实现实现了通常在加密代码中有用的功能,但需要仔细考虑才能正确使用.
tls 程序包tls部分实现了RFC 5246中指定的TLS 1.2和RFC 8446中指定的TLS 1.3.
x509 包x509解析X.509编码的密钥和证书.
pkix 软件包pkix包含用于X.509证书,CRL和OCSP的ASN.1解析和序列化的共享低级结构.