Documentation
¶
Overview ¶
Package sm2 implements SM2 public key encryption, decryption, signing and verification with optional streaming helpers.
Index ¶
- func NewStreamDecrypter(r io.Reader, kp *keypair.Sm2KeyPair) io.Reader
- func NewStreamEncrypter(w io.Writer, kp *keypair.Sm2KeyPair) io.WriteCloser
- func NewStreamSigner(w io.Writer, kp *keypair.Sm2KeyPair) io.WriteCloser
- func NewStreamVerifier(r io.Reader, kp *keypair.Sm2KeyPair) io.WriteCloser
- type DecryptError
- type EncryptError
- type ReadError
- type SignError
- type StdDecrypter
- type StdEncrypter
- type StdSigner
- type StdVerifier
- type StreamDecrypter
- type StreamEncrypter
- type StreamSigner
- type StreamVerifier
- type VerifyError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStreamDecrypter ¶
NewStreamDecrypter creates a Reader that decrypts the entire input from r using the provided key pair, serving plaintext on subsequent Read calls.
func NewStreamEncrypter ¶
func NewStreamEncrypter(w io.Writer, kp *keypair.Sm2KeyPair) io.WriteCloser
NewStreamEncrypter returns a WriteCloser that encrypts all written data with the provided key pair and writes the ciphertext on Close.
func NewStreamSigner ¶ added in v1.2.2
func NewStreamSigner(w io.Writer, kp *keypair.Sm2KeyPair) io.WriteCloser
NewStreamSigner returns a WriteCloser that signs all written data with the provided key pair and writes the signature on Close.
func NewStreamVerifier ¶ added in v1.2.2
func NewStreamVerifier(r io.Reader, kp *keypair.Sm2KeyPair) io.WriteCloser
NewStreamVerifier creates a WriteCloser that verifies data written to it using the signature read from the provided reader.
Types ¶
type DecryptError ¶
type DecryptError struct {
Err error
}
func (DecryptError) Error ¶
func (e DecryptError) Error() string
type EncryptError ¶
type EncryptError struct {
Err error
}
func (EncryptError) Error ¶
func (e EncryptError) Error() string
type StdDecrypter ¶
type StdDecrypter struct {
Error error
// contains filtered or unexported fields
}
StdDecrypter decrypts data using an SM2 private key.
func NewStdDecrypter ¶
func NewStdDecrypter(kp *keypair.Sm2KeyPair) *StdDecrypter
NewStdDecrypter creates a new SM2 decrypter bound to the given key pair.
func (*StdDecrypter) Decrypt ¶
func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)
Decrypt decrypts data with SM2 private key.
type StdEncrypter ¶
type StdEncrypter struct {
Error error
// contains filtered or unexported fields
}
StdEncrypter encrypts data using an SM2 public key. The ciphertext component order is derived from Sm2KeyPair.Order.
func NewStdEncrypter ¶
func NewStdEncrypter(kp *keypair.Sm2KeyPair) *StdEncrypter
NewStdEncrypter creates a new SM2 encrypter bound to the given key pair.
func (*StdEncrypter) Encrypt ¶
func (e *StdEncrypter) Encrypt(src []byte) (dst []byte, err error)
Encrypt encrypts data with SM2 public key.
type StdSigner ¶ added in v1.2.2
type StdSigner struct {
Error error
// contains filtered or unexported fields
}
StdSigner signs data using an SM2 private key.
func NewStdSigner ¶ added in v1.2.2
func NewStdSigner(kp *keypair.Sm2KeyPair) *StdSigner
NewStdSigner creates a new SM2 signer bound to the given key pair.
type StdVerifier ¶ added in v1.2.2
type StdVerifier struct {
Error error
// contains filtered or unexported fields
}
StdVerifier verifies data using an SM2 public key.
func NewStdVerifier ¶ added in v1.2.2
func NewStdVerifier(kp *keypair.Sm2KeyPair) *StdVerifier
NewStdVerifier creates a new SM2 verifier bound to the given key pair.
func (*StdVerifier) Verify ¶ added in v1.2.2
func (v *StdVerifier) Verify(src, sign []byte) (valid bool, err error)
Verify verifies an SM2 signature for the given data.
type StreamDecrypter ¶
type StreamDecrypter struct {
Error error
// contains filtered or unexported fields
}
StreamDecrypter reads all ciphertext from an io.Reader and exposes the decrypted plaintext via Read.
func (*StreamDecrypter) Read ¶
func (d *StreamDecrypter) Read(p []byte) (n int, err error)
Read serves decrypted plaintext from the internal buffer.
type StreamEncrypter ¶
type StreamEncrypter struct {
Error error
// contains filtered or unexported fields
}
StreamEncrypter buffers plaintext and writes SM2 ciphertext on Close.
func (*StreamEncrypter) Close ¶
func (e *StreamEncrypter) Close() error
Close encrypts the buffered plaintext and writes the ciphertext to the underlying writer. If the writer implements io.Closer, it is closed.
func (*StreamEncrypter) Write ¶
func (e *StreamEncrypter) Write(p []byte) (n int, err error)
Write buffers plaintext to be encrypted.
type StreamSigner ¶ added in v1.2.2
type StreamSigner struct {
Error error
// contains filtered or unexported fields
}
StreamSigner buffers data and writes SM2 signature on Close.
func (*StreamSigner) Close ¶ added in v1.2.2
func (s *StreamSigner) Close() error
Close signs the buffered data and writes the signature to the underlying writer. If the writer implements io.Closer, it is closed.
func (*StreamSigner) Write ¶ added in v1.2.2
func (s *StreamSigner) Write(p []byte) (n int, err error)
Write buffers data to be signed.
type StreamVerifier ¶ added in v1.2.2
type StreamVerifier struct {
Error error
// contains filtered or unexported fields
}
StreamVerifier reads signature from an io.Reader and verifies data written to it.
func (*StreamVerifier) Close ¶ added in v1.2.2
func (v *StreamVerifier) Close() error
Close reads the signature from the underlying reader and performs verification.
func (*StreamVerifier) Write ¶ added in v1.2.2
func (v *StreamVerifier) Write(p []byte) (n int, err error)
Write buffers data for verification.
type VerifyError ¶
type VerifyError struct {
Err error
}
func (VerifyError) Error ¶
func (e VerifyError) Error() string
Source Files
¶
- errors.go
- sm2.go