Ejemplo n.º 1
0
 public byte[] Decrypt(string encryptedData)
 {
     byte[] result;
     try
     {
         result = OnPremisePrivateKeyDecryptor.DecryptWithPassword(this.password, encryptedData);
     }
     catch (CryptographicException innerException)
     {
         throw new PrivateKeyDecryptionFailedException("Unable to decrypt TPD private key", innerException);
     }
     return(result);
 }
        private static TrustedDocDomain DecryptTrustedDocDomainData(EncryptedTrustedDocDomain encryptedData, SecureString password)
        {
            IPrivateKeyDecryptor privateKeyDecryptor = new OnPremisePrivateKeyDecryptor(password);

            byte[] buffer = null;
            try
            {
                buffer = privateKeyDecryptor.Decrypt(encryptedData.m_strTrustedDocDomainInfo);
            }
            catch (PrivateKeyDecryptionFailedException innerException)
            {
                throw new TrustedPublishingDomainParser.ParseFailedException("OnPremisePrivateKeyDecryptor.Decrypt() failed", innerException);
            }
            TrustedDocDomain result;

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                try
                {
                    SafeXmlSerializer safeXmlSerializer = new SafeXmlSerializer(typeof(ArrayList), new Type[]
                    {
                        typeof(TrustedDocDomain[])
                    });
                    ArrayList arrayList = safeXmlSerializer.Deserialize(memoryStream) as ArrayList;
                    if (arrayList == null || arrayList.Count != 1)
                    {
                        throw new TrustedPublishingDomainParser.ParseFailedException("DecryptedTPD_NoORMoreThanOneElements");
                    }
                    TrustedDocDomain trustedDocDomain = arrayList[0] as TrustedDocDomain;
                    if (trustedDocDomain == null)
                    {
                        throw new TrustedPublishingDomainParser.ParseFailedException("DecryptedTPD_NotOfType_TrustedDocDomain");
                    }
                    trustedDocDomain.m_ttdki.strEncryptedPrivateKey = encryptedData.m_strKeyData;
                    result = trustedDocDomain;
                }
                catch (InvalidOperationException innerException2)
                {
                    throw new TrustedPublishingDomainParser.ParseFailedException("DecryptedTPD_XmlDeserializationFailed", innerException2);
                }
                catch (XmlException innerException3)
                {
                    throw new TrustedPublishingDomainParser.ParseFailedException("DecryptedTPD_XmlDeserializationFailed", innerException3);
                }
            }
            return(result);
        }