Documentation
¶
Index ¶
- Constants
- Variables
- func AESCBCDecrypt(enc string, key, iv, sealed, aad []byte) ([]byte, error)
- func AESCBCEncrypt(enc string, key, iv, plaintext, aad []byte) ([]byte, error)
- func AESGCMDecrypt(key, nonce, ciphertext, additionalData []byte) ([]byte, error)
- func AESGCMEncrypt(key, nonce, plaintext, additionalData []byte) ([]byte, error)
- func BuildJWECompact(alg, enc string, encryptedKey, iv, sealed []byte) (string, error)
- func BuildJWSCompact(algorithm, keyID, tokenType string, payload, signature []byte, ...) (string, error)
- func BuildSM2SigningInput(protectedHeaders any, payload []byte) ([]byte, error)deprecated
- func BuildSigningInput(protectedHeaders any, payload []byte) ([]byte, error)
- func BytesToPrivateKey(b []byte) (crypto.PublicKey, string, error)
- func DecryptAES(data string, key string) (string, error)
- func DecryptBytesAES(cipherText []byte, key string) ([]byte, error)
- func DecryptBytesSM4(cipherText []byte, key string) ([]byte, error)
- func DecryptJWE(compact string, key interface{}) ([]byte, error)
- func DecryptSM4(data string, key string) (string, error)
- func DispatchContentDecrypt(enc string, key, iv, sealed, aad []byte) ([]byte, error)
- func DispatchContentEncrypt(enc string, key, iv, plaintext, aad []byte) ([]byte, error)
- func DispatchDecryptJWE(compact string, key interface{}, alg string) ([]byte, error)
- func DispatchEncryptJWE(plaintext []byte, key interface{}, alg string) (string, error)
- func EncryptAES(data string, key string) (string, error)
- func EncryptBytesAES(plainText []byte, key string) ([]byte, error)
- func EncryptBytesSM4(plainText []byte, key string) ([]byte, error)
- func EncryptJWE(plaintext []byte, key interface{}, alg, enc string) (string, error)
- func EncryptSM4(data string, key string) (string, error)
- func GetHashAlgorithm(sigAlgorithm string) (hash.Hash, error)
- func HashString(hash hash.Hash, s string, firstHalf bool) string
- func IsSM2Algorithm(alg string) bool
- func IsSM9Algorithm(alg string) bool
- func ParseSM9SignMasterPublicKey(xBase64, yBase64 string) (*sm9.SignMasterPublicKey, error)
- func SM2DecryptJWE(privateKey *sm2.PrivateKey, compact string) ([]byte, error)
- func SM2EncryptJWE(publicKey *ecdsa.PublicKey, plaintext []byte) (string, error)
- func SM2PublicKeyFromJWK(crv, xBase64, yBase64 string) (*ecdsa.PublicKey, error)
- func SM9DecryptJWE(userKey *sm9.EncryptPrivateKey, uid []byte, compact string) ([]byte, error)
- func SM9EncryptJWE(masterPubKey *sm9.EncryptMasterPublicKey, uid []byte, enc string, ...) (string, error)
- func Sign(payload interface{}, signer *Signer) (string, error)
- func SignJWS(payload []byte, key jwk.Key) (string, error)
- func SignPayload(payload []byte, signer *Signer) (string, error)
- func VerifySM2JWSSignature(signingInput []byte, signature []byte, pubKey *ecdsa.PublicKey) error
- func VerifySM9JWSSignature(signingInput []byte, signature []byte, masterPubKey *sm9.SignMasterPublicKey, ...) error
- type ContentDecryptProvider
- type ContentEncryptProvider
- type JWEDecryptProvider
- type JWEEncryptProvider
- type JWEHeader
- type JWKSKey
- type KeyUnwrapPrimitive
- type KeyWrapPrimitive
- type ProviderRegistry
- func (r *ProviderRegistry) GetContentDecryptor(alg string) (ContentDecryptProvider, bool)
- func (r *ProviderRegistry) GetContentEncryptor(alg string) (ContentEncryptProvider, bool)
- func (r *ProviderRegistry) GetJWEDecryptor(alg string) (JWEDecryptProvider, bool)
- func (r *ProviderRegistry) GetJWEEncryptor(alg string) (JWEEncryptProvider, bool)
- func (r *ProviderRegistry) GetSigner(alg string) (SignProvider, bool)
- func (r *ProviderRegistry) GetVerifier(alg string) (VerifyProvider, bool)
- func (r *ProviderRegistry) RegisterContentDecryptor(alg string, p ContentDecryptProvider)
- func (r *ProviderRegistry) RegisterContentEncryptor(alg string, p ContentEncryptProvider)
- func (r *ProviderRegistry) RegisterJWEDecryptor(alg string, p JWEDecryptProvider)
- func (r *ProviderRegistry) RegisterJWEEncryptor(alg string, p JWEEncryptProvider)
- func (r *ProviderRegistry) RegisterSigner(alg string, p SignProvider)
- func (r *ProviderRegistry) RegisterVerifier(alg string, p VerifyProvider)
- type SM2JWK
- type SM9DecryptKey
- type SM9EncryptKey
- type SM9MasterPublicKey
- type SM9SignJWK
- type SM9SignKey
- type SM9VerifyArgs
- type SignPrimitive
- type SignProvider
- type Signer
- type VerifyPrimitive
- type VerifyProvider
Constants ¶
const ( // GM/T 0125.1-2022 algorithm identifiers SGD_SM3_SM2 = "SGD_SM3_SM2" // SM2+SM3 digital signature SGD_SM3_SM9 = "SGD_SM3_SM9" // SM9+SM3 digital signature (identity-based) SGD_SM3_HMAC = "SGD_SM3_HMAC" // SM3 keyed-HMAC SGD_SM2_3 = "SGD_SM2_3" // SM2 public key encryption (JWE key wrapping) SGD_SM9_3 = "SGD_SM9_3" // SM9 encryption (JWE key wrapping) SGD_SM4_CCM = "SGD_SM4_CCM" // SM4 in CCM mode (JWE content encryption) SGD_SM4_GCM = "SGD_SM4_GCM" // SM4 in GCM mode (JWE content encryption) )
const (
AESGCMNonceSize = 12
)
Variables ¶
var ( ErrCipherTextTooShort = errors.New("kexcore/crypto: ciphertext too short") ErrInvalidAESKeySize = errors.New("kexcore/crypto: aes invalid key size, must be 16, 24, or 32 bytes") )
var ( ErrInvalidJWECompact = util.ErrInvalidJWECompact ErrInvalidJWEParts = util.ErrInvalidJWEParts ErrJWEKeyDecrypt = util.ErrJWEKeyDecrypt ErrJWEContentDecrypt = util.ErrJWEContentDecrypt ErrJWEHeaderMismatch = util.ErrJWEHeaderMismatch ErrJWEUnsupportedEnc = util.ErrJWEUnsupportedEnc )
Re-export shared error variables for backward compatibility.
var ( ErrPEMDecode = errors.New("PEM decode failed") ErrUnsupportedFormat = errors.New("key is neither in PKCS#1 nor PKCS#8 format") ErrUnsupportedPrivateKey = errors.New("unsupported key type, must be RSA, ECDSA, ED25519 or SM2 private key") )
var DefaultRegistry = NewProviderRegistry()
DefaultRegistry is the global provider registry. Local gmsm implementations are registered in init().
var ErrUnsupportedAlgorithm = errors.New("unsupported signing algorithm")
Functions ¶
func AESGCMDecrypt ¶
func AESGCMEncrypt ¶
func BuildJWECompact ¶
BuildJWECompact assembles a JWE compact serialization from raw components. This is the single place where JWE formatting happens; both the built-in JWE providers and external wrappers use it.
The sealed parameter is ciphertext||tag (combined output from content encryption).
func BuildJWSCompact ¶
func BuildJWSCompact(algorithm, keyID, tokenType string, payload, signature []byte, extraHeaders map[string]string) (string, error)
BuildJWSCompact assembles a JWS compact serialization from raw components. This is the single place where JWS header construction happens; both the built-in sign providers and external HSM/KMS wrappers use it so that developers only need to supply the cryptographic signature.
extraHeaders is optional; it is merged into the protected header (e.g. SM9 uid).
func BuildSM2SigningInput
deprecated
BuildSM2SigningInput reconstructs the JWS signing input from the protected header and payload of a JWS message. Returns base64url(header) + "." + base64url(payload). protectedHeaders can be any value that json.Marshal can handle (e.g. jws.Headers).
Deprecated: Use BuildSigningInput instead. This function is kept for backward compatibility.
func BuildSigningInput ¶
BuildSigningInput reconstructs the JWS signing input from the protected header and payload of a JWS message. Returns base64url(header) + "." + base64url(payload). protectedHeaders can be any value that json.Marshal can handle (e.g. jws.Headers).
func DecryptJWE ¶
DecryptJWE decrypts a JWE compact serialization. It checks the ProviderRegistry first for HSM/KMS overrides, then falls back to the built-in software implementation.
func DispatchContentDecrypt ¶
DispatchContentDecrypt routes content decryption through ProviderRegistry.
func DispatchContentEncrypt ¶
DispatchContentEncrypt routes content encryption through ProviderRegistry.
func DispatchDecryptJWE ¶
DispatchDecryptJWE routes JWE decryption through ProviderRegistry.
func DispatchEncryptJWE ¶
DispatchEncryptJWE routes JWE encryption through ProviderRegistry.
func EncryptJWE ¶
EncryptJWE encrypts plaintext using the specified JWE algorithms. It checks the ProviderRegistry first for HSM/KMS overrides, then falls back to the built-in software implementation via crypto/provider/std.
func IsSM2Algorithm ¶
IsSM2Algorithm returns true if the given algorithm identifier is an SM2 signing algorithm (SGD_SM3_SM2 or SM2-SM3 alias).
func IsSM9Algorithm ¶
IsSM9Algorithm returns true if the given algorithm identifier is an SM9 signing algorithm (SGD_SM3_SM9).
func ParseSM9SignMasterPublicKey ¶
func ParseSM9SignMasterPublicKey(xBase64, yBase64 string) (*sm9.SignMasterPublicKey, error)
ParseSM9SignMasterPublicKey parses an SM9 signing master public key from JWK x and y fields.
func SM2DecryptJWE ¶
func SM2DecryptJWE(privateKey *sm2.PrivateKey, compact string) ([]byte, error)
func SM2EncryptJWE ¶
func SM2PublicKeyFromJWK ¶
SM2PublicKeyFromJWK parses an SM2 public key from JWK fields.
func SM9DecryptJWE ¶
func SM9EncryptJWE ¶
func SignJWS ¶
SignJWS signs the payload using the given JWK and returns compact JWS serialization. The JWK must contain a private key and have an "alg" header set.
This is the recommended entry point for JWS signing. It delegates to Signer, which checks the ProviderRegistry first for HSM/KMS overrides, then falls back to the built-in software implementation (gmsm for GM/T, jwx for international algorithms).
func SignPayload ¶
SignPayload signs raw payload bytes.
func VerifySM2JWSSignature ¶
VerifySM2JWSSignature verifies an SM2 JWS signature using SM3 hash. This function handles the full verification flow: decode the signature, reconstruct the signing input, hash with SM3, and verify with SM2.
Parameters:
- signingInput: the JWS signing input (base64url(header) + "." + base64url(payload))
- signature: the raw signature bytes from the JWS
- pubKey: the SM2 public key for verification
func VerifySM9JWSSignature ¶
func VerifySM9JWSSignature(signingInput []byte, signature []byte, masterPubKey *sm9.SignMasterPublicKey, uid []byte) error
VerifySM9JWSSignature verifies an SM9 JWS signature using SM3 hash. SM9 verification requires the master public key and the user identifier (uid). The uid must be extracted from the JWS protected header (custom "uid" parameter).
Parameters:
- signingInput: the JWS signing input (base64url(header) + "." + base64url(payload))
- signature: the raw signature bytes from the JWS
- masterPubKey: the SM9 signing master public key
- uid: the user identifier used to derive the signing key
Types ¶
type ContentDecryptProvider ¶
type ContentDecryptProvider interface {
// Algorithm returns the JWE content encryption algorithm.
Algorithm() string
// Decrypt decrypts ciphertext with the given key, IV, and AAD.
// Input sealed is ciphertext + GCM tag concatenated.
Decrypt(ctx context.Context, key, iv, sealed, aad []byte) ([]byte, error)
}
ContentDecryptProvider is the interface for external JWE content decryption implementations.
type ContentEncryptProvider ¶
type ContentEncryptProvider interface {
// Algorithm returns the JWE content encryption algorithm, e.g. "SGD_SM4_GCM", "A256GCM".
Algorithm() string
// Encrypt encrypts plaintext with the given key, IV, and AAD.
// Returns ciphertext + GCM tag concatenated.
Encrypt(ctx context.Context, key, iv, plaintext, aad []byte) ([]byte, error)
}
ContentEncryptProvider is the interface for external JWE content encryption implementations. Used for "dir" mode where key wrapping is "dir" and content encryption is the actual algorithm. HSM/KMS vendors can implement this to provide hardware-accelerated content encryption.
type JWEDecryptProvider ¶
type JWEDecryptProvider interface {
// KeyAlgorithm returns the JWE key wrapping algorithm.
KeyAlgorithm() string
// Decrypt decrypts JWE compact serialization and returns plaintext.
// key is the decryption key material (type depends on algorithm).
Decrypt(ctx context.Context, compact string, key interface{}) ([]byte, error)
}
JWEDecryptProvider is the interface for external JWE decryption implementations.
func WrapKeyUnwrapPrimitive ¶
func WrapKeyUnwrapPrimitive(alg string, p KeyUnwrapPrimitive) JWEDecryptProvider
WrapKeyUnwrapPrimitive wraps a KeyUnwrapPrimitive into a JWEDecryptProvider.
type JWEEncryptProvider ¶
type JWEEncryptProvider interface {
// KeyAlgorithm returns the JWE key wrapping algorithm, e.g. "SGD_SM2_3".
KeyAlgorithm() string
// ContentEncryption returns the JWE content encryption algorithm, e.g. "SGD_SM4_GCM".
ContentEncryption() string
// Encrypt encrypts plaintext and returns JWE compact serialization.
// key is the encryption key material (type depends on algorithm).
Encrypt(ctx context.Context, plaintext []byte, key interface{}) (string, error)
}
JWEEncryptProvider is the interface for external JWE encryption implementations.
func WrapKeyWrapPrimitive ¶
func WrapKeyWrapPrimitive(alg, enc string, p KeyWrapPrimitive) JWEEncryptProvider
WrapKeyWrapPrimitive wraps a KeyWrapPrimitive into a JWEEncryptProvider. The SDK generates the IV, encrypts the content with the CEK, and assembles the JWE compact serialization; the primitive only wraps the key.
type JWKSKey ¶
JWKSKey represents a parsed key from a JWKS endpoint. The Key field is one of: *ecdsa.PublicKey (SM2), *sm9.SignMasterPublicKey (SM9). Standard keys (RSA, ECDSA, EdDSA) are NOT handled here — use jwx for those.
func FindJWKSKey ¶
FindJWKSKey finds a key by kid and algorithm from a parsed JWKS key list.
func ParseJWKSBytes ¶
ParseJWKSBytes parses JWKS JSON and returns keys with GM/T algorithms (SGD_SM3_SM2, SGD_SM3_SM9). Standard algorithm keys are skipped — use jwx for those.
type KeyUnwrapPrimitive ¶
type KeyUnwrapPrimitive interface {
// UnwrapKey unwraps the wrapped key bytes and returns the raw CEK.
UnwrapKey(ctx context.Context, key interface{}, wrappedKey []byte, keySize int) (cek []byte, err error)
}
KeyUnwrapPrimitive is the minimal JWE key-unwrapping interface.
type KeyWrapPrimitive ¶
type KeyWrapPrimitive interface {
// WrapKey wraps a CEK of the given size with the provided key.
// Returns the raw CEK and the wrapped key bytes.
WrapKey(ctx context.Context, key interface{}, keySize int) (cek, wrappedKey []byte, err error)
}
KeyWrapPrimitive is the minimal JWE key-wrapping interface. Implement this when your HSM/KMS provides key wrapping and you want the SDK to handle CEK generation, content encryption, and JWE compact assembly.
WrapKey takes the wrapping key and desired CEK size, generates (or obtains) a content encryption key, wraps it with the wrapping key, and returns both.
type ProviderRegistry ¶
type ProviderRegistry struct {
// contains filtered or unexported fields
}
ProviderRegistry holds registered cryptographic providers. It is the central dispatch point for algorithm-specific implementations.
func NewProviderRegistry ¶
func NewProviderRegistry() *ProviderRegistry
NewProviderRegistry creates a new empty ProviderRegistry.
func (*ProviderRegistry) GetContentDecryptor ¶
func (r *ProviderRegistry) GetContentDecryptor(alg string) (ContentDecryptProvider, bool)
GetContentDecryptor returns the registered ContentDecryptProvider for the content encryption algorithm.
func (*ProviderRegistry) GetContentEncryptor ¶
func (r *ProviderRegistry) GetContentEncryptor(alg string) (ContentEncryptProvider, bool)
GetContentEncryptor returns the registered ContentEncryptProvider for the content encryption algorithm.
func (*ProviderRegistry) GetJWEDecryptor ¶
func (r *ProviderRegistry) GetJWEDecryptor(alg string) (JWEDecryptProvider, bool)
GetJWEDecryptor returns the registered JWEDecryptProvider for the key algorithm.
func (*ProviderRegistry) GetJWEEncryptor ¶
func (r *ProviderRegistry) GetJWEEncryptor(alg string) (JWEEncryptProvider, bool)
GetJWEEncryptor returns the registered JWEEncryptProvider for the key algorithm.
func (*ProviderRegistry) GetSigner ¶
func (r *ProviderRegistry) GetSigner(alg string) (SignProvider, bool)
GetSigner returns the registered SignProvider for the algorithm.
func (*ProviderRegistry) GetVerifier ¶
func (r *ProviderRegistry) GetVerifier(alg string) (VerifyProvider, bool)
GetVerifier returns the registered VerifyProvider for the algorithm.
func (*ProviderRegistry) RegisterContentDecryptor ¶
func (r *ProviderRegistry) RegisterContentDecryptor(alg string, p ContentDecryptProvider)
RegisterContentDecryptor registers a ContentDecryptProvider for the given content encryption algorithm.
func (*ProviderRegistry) RegisterContentEncryptor ¶
func (r *ProviderRegistry) RegisterContentEncryptor(alg string, p ContentEncryptProvider)
RegisterContentEncryptor registers a ContentEncryptProvider for the given content encryption algorithm.
func (*ProviderRegistry) RegisterJWEDecryptor ¶
func (r *ProviderRegistry) RegisterJWEDecryptor(alg string, p JWEDecryptProvider)
RegisterJWEDecryptor registers a JWEDecryptProvider for the given key algorithm.
func (*ProviderRegistry) RegisterJWEEncryptor ¶
func (r *ProviderRegistry) RegisterJWEEncryptor(alg string, p JWEEncryptProvider)
RegisterJWEEncryptor registers a JWEEncryptProvider for the given key algorithm.
func (*ProviderRegistry) RegisterSigner ¶
func (r *ProviderRegistry) RegisterSigner(alg string, p SignProvider)
RegisterSigner registers a SignProvider for the given algorithm.
func (*ProviderRegistry) RegisterVerifier ¶
func (r *ProviderRegistry) RegisterVerifier(alg string, p VerifyProvider)
RegisterVerifier registers a VerifyProvider for the given algorithm.
type SM2JWK ¶
type SM2JWK struct {
Kty string `json:"kty"`
Crv string `json:"crv"`
X string `json:"x"`
Y string `json:"y"`
Alg string `json:"alg,omitempty"`
Kid string `json:"kid,omitempty"`
Use string `json:"use,omitempty"`
}
SM2JWK represents a JSON Web Key for an SM2 public key per GM/T 0125.4-2022. SM2 keys use kty "EC" with crv "SM2-P-256" and standard x/y coordinates. This type exists because the jwx library does not recognize the SM2 curve or the SGD_SM3_SM2 algorithm, so we cannot use jwk.Import or jwk.ParseKey.
type SM9DecryptKey ¶
type SM9DecryptKey struct {
PrivateKey *sm9.EncryptPrivateKey
UID []byte
}
SM9DecryptKey wraps an SM9 encryption user private key and UID for JWE decryption.
type SM9EncryptKey ¶
type SM9EncryptKey interface {
// Resolve returns the SM9 master public key and UID for encryption.
Resolve() (masterPubKey *sm9.EncryptMasterPublicKey, uid []byte, err error)
}
SM9EncryptKey is the crypto-layer interface for SM9 encryption keys. It abstracts away the gmsm-specific types so that callers (protocol layer) do not need to import gmsm directly.
type SM9MasterPublicKey ¶
type SM9MasterPublicKey struct {
PublicKey *sm9.EncryptMasterPublicKey
UID []byte
}
SM9MasterPublicKey wraps an SM9 encryption master public key and UID to implement the SM9EncryptKey interface. It also implements protocol.SM9EncryptKey (MarshalBinary + UID).
func (*SM9MasterPublicKey) GetUID ¶
func (k *SM9MasterPublicKey) GetUID() []byte
func (*SM9MasterPublicKey) MarshalBinary ¶
func (k *SM9MasterPublicKey) MarshalBinary() ([]byte, error)
func (*SM9MasterPublicKey) Resolve ¶
func (k *SM9MasterPublicKey) Resolve() (*sm9.EncryptMasterPublicKey, []byte, error)
type SM9SignJWK ¶
type SM9SignJWK struct {
Kty string `json:"kty"`
Crv string `json:"crv"`
X string `json:"x"`
Y string `json:"y"`
Hid int `json:"hid"`
Alg string `json:"alg,omitempty"`
Kid string `json:"kid,omitempty"`
Use string `json:"use,omitempty"`
}
SM9SignJWK represents a JSON Web Key for an SM9 signing master public key. SM9 uses identity-based cryptography (IBC) where the master public key is used for verification and user signing keys are derived from the master key + uid. The kid field serves as the identity identifier.
func NewSM9SignJWK ¶
func NewSM9SignJWK(masterPubKey *sm9.SignMasterPublicKey, kid, use string, hid int) (SM9SignJWK, error)
NewSM9SignJWK constructs an SM9SignJWK from an SM9 signing master public key. The hid parameter is the SM9 private key generation function identifier (1 for signing, 3 for encryption).
type SM9SignKey ¶
type SM9SignKey struct {
PrivateKey *sm9.SignPrivateKey
UID []byte
}
SM9SignKey wraps the SM9 signing key material with the user identifier. It is passed as the key argument to stdSm9SignProvider.Sign.
type SM9VerifyArgs ¶
type SM9VerifyArgs struct {
MasterPubKey *sm9.SignMasterPublicKey
UID []byte
}
SM9VerifyArgs holds the arguments needed for SM9 signature verification.
type SignPrimitive ¶
type SignPrimitive interface {
// Sign signs the pre-computed digest and returns the raw signature bytes.
// The SDK has already applied the correct hash algorithm for the given keyID.
Sign(ctx context.Context, keyID string, digest []byte) ([]byte, error)
}
SignPrimitive is the minimal signing interface. Implement this when your HSM/KMS provides Sign(digest) -> signature and you want the SDK to handle hashing, JWS header construction, and compact serialization.
type SignProvider ¶
type SignProvider interface {
// Algorithm returns the supported JWA signature algorithm, e.g. "SGD_SM3_SM2".
Algorithm() string
// Sign signs the payload and returns compact JWS.
// key is the signing key material; type depends on algorithm (e.g. *sm2.PrivateKey for SM2).
// tokenType is the JWT typ header value (e.g. "JWT", "logout+jwt"); HSM providers may ignore it.
// HSM/KMS providers can ignore key if they locate key material by keyID internally.
Sign(ctx context.Context, keyID, tokenType string, key interface{}, payload []byte) (string, error)
}
SignProvider is the interface for JWS signing implementations. Both built-in software signers and HSM/KMS vendors implement this interface and register it to DefaultRegistry. The last registration wins, so HSM/KMS providers registered in init() will override the built-in ones.
func WrapSignPrimitive ¶
func WrapSignPrimitive(alg string, p SignPrimitive) SignProvider
WrapSignPrimitive wraps a SignPrimitive into a SignProvider. The SDK computes the hash digest and assembles the JWS compact serialization; the primitive only performs the raw cryptographic signing operation.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer encapsulates key material and algorithm for JWS signing operations.
func NewSigner ¶
NewSigner creates a Signer for the given algorithm and key. The algorithm must be a valid JWA signature algorithm string (e.g. "RS256", "ES384", "EdDSA", "SGD_SM3_SM2").
For SM9 signing (SGD_SM3_SM9), key must be a *sm9.SignPrivateKey and the Signer must be configured with the user identifier (uid) via Signer.SetSM9UID before signing.
func (*Signer) SetSM9UID ¶
SetSM9UID sets the user identifier (uid) for SM9 signing. This must be called before Sign when using SGD_SM3_SM9 algorithm.
func (*Signer) SetTokenType ¶
SetTokenType sets the JWT typ header value (e.g. "JWT", "logout+jwt"). If empty, the default "JWT" is used.
func (*Signer) Sign ¶
Sign signs the payload and returns the compact serialized JWS. Sign signs the payload and returns the compact serialized JWS. It checks the ProviderRegistry first for HSM/KMS overrides (any algorithm), then falls back to the built-in software implementation (gmsm for GM/T, jwx for international algorithms).
type VerifyPrimitive ¶
type VerifyPrimitive interface {
// Verify verifies the signature against the signing input (header.payload bytes).
// key is the public key material (type depends on algorithm).
Verify(ctx context.Context, signingInput, signature []byte, key interface{}) error
}
VerifyPrimitive is the minimal verification interface.
type VerifyProvider ¶
type VerifyProvider interface {
// Algorithm returns the supported JWA signature algorithm.
Algorithm() string
// Verify verifies the signature for the given signing input.
// key is the public key material (type depends on algorithm, e.g. *ecdsa.PublicKey for SM2).
Verify(ctx context.Context, signingInput, signature []byte, key interface{}) error
}
VerifyProvider is the interface for external JWS signature verification.
func WrapVerifyPrimitive ¶
func WrapVerifyPrimitive(alg string, p VerifyPrimitive) VerifyProvider
WrapVerifyPrimitive wraps a VerifyPrimitive into a VerifyProvider.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
provider
|
|
|
std
Package std provides standard (international) JWE algorithm implementations backed by lestrrat-go/jwx.
|
Package std provides standard (international) JWE algorithm implementations backed by lestrrat-go/jwx. |
|
Package util provides shared JWE types and parsing functions used by both the crypto package (public API) and crypto/provider/std (implementations).
|
Package util provides shared JWE types and parsing functions used by both the crypto package (public API) and crypto/provider/std (implementations). |