public static byte[] GetSecretKey(EncryptedKey encryptedKey, AsymmetricAlgorithm privateKey)
{
var keyAlgorithm = encryptedKey.EncryptionMethod.KeyAlgorithm;
var asymmetricAlgorithm = GetAsymmetricKeyTransportAlgorithm(keyAlgorithm);
asymmetricAlgorithm.FromXmlString(privateKey.ToXmlString(true));
var useOaep = keyAlgorithm == EncryptedXml.XmlEncRSAOAEPUrl;
return asymmetricAlgorithm.Decrypt(encryptedKey.CipherData.CipherValue, useOaep);
}