Esempio n. 1
0
        /// <summary>
        ///     Gets the certificate.
        /// </summary>
        /// <value>
        ///     The certificate.
        /// </value>
        public X509Certificate2 Load(IFileInfo certificatePath, string passPhrase)
        {
            var mappedPath = _mapper != null?_mapper.Map(certificatePath) : certificatePath;

            try
            {
                var reader = new FileReader();
                var bytes  = reader.ReadBytes(mappedPath);
                // The key storage is really important as without it, it won't work when run from IIS
                var certificate = new X509Certificate2(bytes, passPhrase,
                                                       X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet);
                _logger.InfoFormat("Certificate loaded from {0}", mappedPath);
                return(certificate);
            }
            catch (CryptographicException e)
            {
                // Get the path in the exception
                throw new CryptographicException("In " + mappedPath + ": " + e.Message);
            }
        }