mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
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)
|
||
|
}
|