mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
f0d77ab3db
This relates to #12577 --------- Co-authored-by: gillespi314 <73313222+gillespi314@users.noreply.github.com> Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
26 lines
519 B
Go
26 lines
519 B
Go
package mdm
|
|
|
|
import (
|
|
"crypto"
|
|
"crypto/x509"
|
|
"encoding/base64"
|
|
|
|
"go.mozilla.org/pkcs7"
|
|
)
|
|
|
|
// DecryptBase64CMS decrypts a base64 encoded pkcs7-encrypted value using the
|
|
// provided certificate and private key.
|
|
func DecryptBase64CMS(p7Base64 string, cert *x509.Certificate, key crypto.PrivateKey) ([]byte, error) {
|
|
p7Bytes, err := base64.StdEncoding.DecodeString(p7Base64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
p7, err := pkcs7.Parse(p7Bytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return p7.Decrypt(cert, key)
|
|
}
|