Documentation ¶
Index ¶
- Variables
- func Decrypt(privateKey []byte, doc []byte) ([]byte, error)
- func Encrypt(publicKey, doc []byte, opts EncryptOptions) ([]byte, error)
- func Sign(key []byte, doc []byte, opts SignatureOptions) ([]byte, error)
- func Verify(publicKey []byte, doc []byte, opts SignatureOptions) error
- type CipherType
- type DigestAlgorithmType
- type EncryptOptions
- type Method
- type SessionCipherType
- type Signature
- type SignatureOptions
- type SignatureX509Data
- type XMLIDOption
Constants ¶
This section is empty.
Variables ¶
var ErrVerificationFailed = errors.New("signature verification failed")
ErrVerificationFailed is returned from Verify when the signature is incorrect
Functions ¶
func Decrypt ¶
Decrypt finds the first encrypted part of doc, decrypts it using privateKey and returns the plaintext of the embedded document.
func Encrypt ¶
func Encrypt(publicKey, doc []byte, opts EncryptOptions) ([]byte, error)
Encrypt encrypts the XML document to publicKey and returns the encrypted document.
func Sign ¶
func Sign(key []byte, doc []byte, opts SignatureOptions) ([]byte, error)
Sign returns a version of doc signed with key according to the XMLDSIG standard. doc is a template document meaning that it contains an `http://www.w3.org/2000/09/xmldsig#Signature` element whose properties define how and what to sign.
func Verify ¶
func Verify(publicKey []byte, doc []byte, opts SignatureOptions) error
Verify checks that the signature in doc is valid according to the XMLDSIG specification. publicKey is the public part of the key used to sign doc. If the signature is not correct, this function returns ErrVerificationFailed.
Types ¶
type CipherType ¶
type CipherType int
CipherType represent which cipher to use to encrypt the document
const ( // DefaultCipher (the zero value) represents the default cipher, RSA-OAEP DefaultCipher CipherType = iota // RsaOaep means the cipher should be RSA-OAEP RsaOaep // RsaPkcs1 means the cipher should be RSA-PKCS1 RsaPkcs1 )
type DigestAlgorithmType ¶
type DigestAlgorithmType int
DigestAlgorithmType represent which digest algorithm to use when encrypting the document.
const ( // DefaultDigestAlgorithm (the zero value) represents the default cipher, SHA1 DefaultDigestAlgorithm DigestAlgorithmType = iota // Sha1 means the digest algorithm should be SHA-1 Sha1 // Sha256 means the digest algorithm should be SHA-256 Sha256 // Sha384 means the digest algorithm should be SHA-384 Sha384 // Sha512 means the digest algorithm should be SHA-512 Sha512 )
type EncryptOptions ¶
type EncryptOptions struct { SessionCipher SessionCipherType Cipher CipherType DigestAlgorithm DigestAlgorithmType }
EncryptOptions specifies the ciphers to use to encrypt the document.
type SessionCipherType ¶
type SessionCipherType int
SessionCipherType represents which session cipher to use to encrypt the document.
const ( // DefaultSessionCipher (the zero value) represents the default session cipher, AES256-CBC DefaultSessionCipher SessionCipherType = iota // Aes128Cbc means the session cipher should be AES-128 in CBC mode. Aes128Cbc // Aes192Cbc means the session cipher should be AES-192 in CBC mode. Aes192Cbc // Aes256Cbc means the session cipher should be AES-256 in CBC mode. Aes256Cbc // Des3Cbc means the session cipher should be triple DES in CBC mode. Des3Cbc )
type Signature ¶
type Signature struct { XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature"` CanonicalizationMethod Method `xml:"SignedInfo>CanonicalizationMethod"` SignatureMethod Method `xml:"SignedInfo>SignatureMethod"` ReferenceTransforms []Method `xml:"SignedInfo>Reference>Transforms>Transform"` DigestMethod Method `xml:"SignedInfo>Reference>DigestMethod"` DigestValue string `xml:"SignedInfo>Reference>DigestValue"` SignatureValue string `xml:"SignatureValue"` KeyName string `xml:"KeyInfo>KeyName,omitempty"` X509Certificate *SignatureX509Data `xml:"KeyInfo>X509Data,omitempty"` }
Signature is a model for the Signature object specified by XMLDSIG. This is convenience object when constructing XML that you'd like to sign. For example:
type Foo struct { Stuff string Signature Signature } f := Foo{Suff: "hello"} f.Signature = DefaultSignature() buf, _ := xml.Marshal(f) buf, _ = Sign(key, buf)
func DefaultSignature ¶
DefaultSignature returns a Signature struct that uses the default c14n and SHA1 settings.
type SignatureOptions ¶
type SignatureOptions struct { // Specify the name of ID attributes for specific elements. This // may be required if the signed document contains Reference elements // that define which parts of the document are to be signed. // // https://www.aleksey.com/xmlsec/faq.html#section_3_2 // http://www.w3.org/TR/xml-id/ // http://xmlsoft.org/html/libxml-valid.html#xmlAddID XMLID []XMLIDOption }
SignatureOptions represents additional, less commonly used, options for Sign and Verify
type SignatureX509Data ¶
type SignatureX509Data struct {
X509Certificate string `xml:"X509Certificate,omitempty"`
}
SignatureX509Data represents the <X509Data> element of <Signature>
type XMLIDOption ¶
XMLIDOption represents the definition of an XML reference element (See http://www.w3.org/TR/xml-id/)