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)
| 76 | // EncryptedKey is never followed into another EncryptedKey: see |
| 77 | // ErrKeyAlgorithmNotAllowed. |
| 78 | func 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 | |
| 96 | func getCiphertext(encryptedKey *etree.Element) ([]byte, error) { |
| 97 | ciphertextEl := encryptedKey.FindElement("./CipherData/CipherValue") |