Documentation
¶
Overview ¶
Package sm2 implements SM2 public key encryption and decryption 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
- type DecryptError
- type EncryptError
- type KeyPairError
- type NilKeyPairError
- type NoSignatureError
- type PrivateKeyUnsetError
- type PublicKeyUnsetError
- type ReadError
- type SignError
- type StdDecrypter
- type StdEncrypter
- type StreamDecrypter
- type StreamEncrypter
- 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.
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 KeyPairError ¶
type KeyPairError struct{ Err error }
func (KeyPairError) Error ¶
func (e KeyPairError) Error() string
type NilKeyPairError ¶
type NilKeyPairError struct{}
func (NilKeyPairError) Error ¶
func (e NilKeyPairError) Error() string
type NoSignatureError ¶
type NoSignatureError struct{}
func (NoSignatureError) Error ¶
func (e NoSignatureError) Error() string
type PrivateKeyUnsetError ¶
type PrivateKeyUnsetError struct{}
func (PrivateKeyUnsetError) Error ¶
func (e PrivateKeyUnsetError) Error() string
type PublicKeyUnsetError ¶
type PublicKeyUnsetError struct{}
func (PublicKeyUnsetError) Error ¶
func (e PublicKeyUnsetError) 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 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 VerifyError ¶
type VerifyError struct{ Err error }
func (VerifyError) Error ¶
func (e VerifyError) Error() string
Source Files
¶
- errors.go
- sm2.go