ARO-RP/vendor/go.mozilla.org/pkcs7
darthhexx 1c4e98933e Vendor installer release 4.10
Switches to go.1.17, OCP 4.10, and Kubernetes 1.23 modules.
2022-05-25 14:49:12 +10:00
..
.gitignore move to go.mod, add deps.go, upgrade dependencies, vendor 2020-11-06 11:35:56 -06:00
LICENSE move to go.mod, add deps.go, upgrade dependencies, vendor 2020-11-06 11:35:56 -06:00
Makefile move to go.mod, add deps.go, upgrade dependencies, vendor 2020-11-06 11:35:56 -06:00
README.md make vendor 2021-09-08 15:53:40 +01:00
ber.go make vendor 2021-09-08 15:53:40 +01:00
decrypt.go move to go.mod, add deps.go, upgrade dependencies, vendor 2020-11-06 11:35:56 -06:00
encrypt.go make vendor 2021-09-08 15:53:40 +01:00
pkcs7.go move to go.mod, add deps.go, upgrade dependencies, vendor 2020-11-06 11:35:56 -06:00
sign.go make vendor 2021-09-08 15:53:40 +01:00
verify.go make vendor 2021-09-08 15:53:40 +01:00
verify_test_dsa.go make vendor 2021-09-08 15:53:40 +01:00

README.md

pkcs7

GoDoc Build Status

pkcs7 implements parsing and creating signed and enveloped messages.

package main

import (
	"bytes"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"os"

    "go.mozilla.org/pkcs7"
)

func SignAndDetach(content []byte, cert *x509.Certificate, privkey *rsa.PrivateKey) (signed []byte, err error) {
	toBeSigned, err := NewSignedData(content)
	if err != nil {
		err = fmt.Errorf("Cannot initialize signed data: %s", err)
		return
	}
	if err = toBeSigned.AddSigner(cert, privkey, SignerInfoConfig{}); err != nil {
		err = fmt.Errorf("Cannot add signer: %s", err)
		return
	}

	// Detach signature, omit if you want an embedded signature
	toBeSigned.Detach()

	signed, err = toBeSigned.Finish()
	if err != nil {
		err = fmt.Errorf("Cannot finish signing data: %s", err)
		return
	}

	// Verify the signature
	pem.Encode(os.Stdout, &pem.Block{Type: "PKCS7", Bytes: signed})
	p7, err := pkcs7.Parse(signed)
	if err != nil {
		err = fmt.Errorf("Cannot parse our signed data: %s", err)
		return
	}

	// since the signature was detached, reattach the content here
	p7.Content = content

	if bytes.Compare(content, p7.Content) != 0 {
		err = fmt.Errorf("Our content was not in the parsed data:\n\tExpected: %s\n\tActual: %s", content, p7.Content)
		return
	}
	if err = p7.Verify(); err != nil {
		err = fmt.Errorf("Cannot verify our signed data: %s", err)
		return
	}

	return signed, nil
}

Credits

This is a fork of fullsailor/pkcs7