Exemplo n.º 1
0
        /// <summary>
        /// Decrypts the specified encoded encrypted message. This is for decoding received messages
        /// </summary>
        /// <param name="encodedEncryptedMessage">The encoded encrypted message.</param>
        /// <returns></returns>
        internal static byte[] Decrypt(byte[] encodedEncryptedMessage)
        {
            try
            {
                if (receivers_pfx == null)
                {
                    receivers_pfx = new X509Certificate2(ConfigValues.RecipientCertFilename, ConfigValues.RecipientCertPassword);
                }

                var certificateCollection = new X509Certificate2Collection(receivers_pfx);

                EnvelopedCms envelopedCms = new EnvelopedCms();
                envelopedCms.Decode(encodedEncryptedMessage);
                envelopedCms.Decrypt(certificateCollection);
                string s = envelopedCms.ToString();
                return(envelopedCms.Encode());
            }
            catch (Exception ex)
            {
                Log.Error($"Decrypt Exception occured : {ex.Message}");
                throw;
            }
        }