MCPcopy Create free account
hub / github.com/crewjam/saml / Decrypt

Function Decrypt

xmlenc/decrypt.go:78–94  ·  view source on GitHub ↗

Decrypt decrypts the encrypted data using the provided key. If the data are encrypted using AES, then the key should be a []byte. If the data are encrypted with RSA-OAEP-MGF1P or RSA-OAEP then key should be a *rsa.PrivateKey. The algorithm is the one the EncryptionMethod of ciphertextEl names, amon

(key interface{}, ciphertextEl *etree.Element)

Source from the content-addressed store, hash-verified

76// EncryptedKey is never followed into another EncryptedKey: see
77// ErrKeyAlgorithmNotAllowed.
78func Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error) {
79 encryptionMethodEl := ciphertextEl.FindElement("./EncryptionMethod")
80 if encryptionMethodEl == nil {
81 return nil, ErrCannotFindRequiredElement("EncryptionMethod")
82 }
83 algorithm := encryptionMethodEl.SelectAttrValue("Algorithm", "")
84 decrypter, ok := lookupDecrypter(algorithm)
85 if !ok {
86 return nil, ErrAlgorithmNotImplemented(algorithm)
87 }
88 if ciphertextEl.Tag == "EncryptedKey" {
89 if _, isBlockCipher := decrypter.(BlockCipher); isBlockCipher {
90 return nil, ErrKeyAlgorithmNotAllowed(algorithm)
91 }
92 }
93 return decrypter.Decrypt(key, ciphertextEl)
94}
95
96func getCiphertext(encryptedKey *etree.Element) ([]byte, error) {
97 ciphertextEl := encryptedKey.FindElement("./CipherData/CipherValue")

Calls 5

lookupDecrypterFunction · 0.85
ErrKeyAlgorithmNotAllowedTypeAlias · 0.85
DecryptMethod · 0.65