目录

bccsp.go

优质
小牛编辑
133浏览
2023-12-01

bccsp.go

  • BCCSP 接口:定义密码学相关操作,包括加解密、签名和验证、签名、Hash、Key 的生命周期管理等方法。
type BCCSP interface {    // KeyGen generates a key using opts.    KeyGen(opts KeyGenOpts) (k Key, err error)    // KeyDeriv derives a key from k using opts.    // The opts argument should be appropriate for the primitive used.    KeyDeriv(k Key, opts KeyDerivOpts) (dk Key, err error)    // KeyImport imports a key from its raw representation using opts.    // The opts argument should be appropriate for the primitive used.    KeyImport(raw interface{}, opts KeyImportOpts) (k Key, err error)    // GetKey returns the key this CSP associates to    // the Subject Key Identifier ski.    GetKey(ski []byte) (k Key, err error)    // Hash hashes messages msg using options opts.    // If opts is nil, the default hash function will be used.    Hash(msg []byte, opts HashOpts) (hash []byte, err error)    // GetHash returns and instance of hash.Hash using options opts.    // If opts is nil, the default hash function will be returned.    GetHash(opts HashOpts) (h hash.Hash, err error)    // Sign signs digest using key k.    // The opts argument should be appropriate for the algorithm used.    //    // 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).    Sign(k Key, digest []byte, opts SignerOpts) (signature []byte, err error)    // Verify verifies signature against key k and digest    // The opts argument should be appropriate for the algorithm used.    Verify(k Key, signature, digest []byte, opts SignerOpts) (valid bool, err error)    // Encrypt encrypts plaintext using key k.    // The opts argument should be appropriate for the algorithm used.    Encrypt(k Key, plaintext []byte, opts EncrypterOpts) (ciphertext []byte, err error)    // Decrypt decrypts ciphertext using key k.    // The opts argument should be appropriate for the algorithm used.    Decrypt(k Key, ciphertext []byte, opts DecrypterOpts) (plaintext []byte, err error)}