Exemplo n.º 1
0
 private static void ThrowIfKeyTypeInvalid(KeyInformation keyInfo, string tpdName, out object failureTarget)
 {
     RmsUtil.ThrowIfParameterNull(keyInfo, "keyInfo");
     RmsUtil.ThrowIfStringParameterNullOrEmpty(tpdName, "tpdName");
     failureTarget = null;
     if (string.IsNullOrEmpty(keyInfo.strIDType))
     {
         failureTarget = tpdName;
         throw new NoKeyIDTypeInImportedTrustedPublishingDomainException();
     }
 }
Exemplo n.º 2
0
 private static KeyInformation ConvertFromRmsOnlineKeyInformation(KeyInformation rmsoKeyInfo)
 {
     RmsUtil.ThrowIfParameterNull(rmsoKeyInfo, "rmsoKeyInfo");
     return(new KeyInformation
     {
         strID = rmsoKeyInfo.strID,
         strIDType = rmsoKeyInfo.strIDType,
         nCSPType = rmsoKeyInfo.nCSPType,
         strCSPName = rmsoKeyInfo.strCSPName,
         strKeyContainerName = rmsoKeyInfo.strKeyContainerName,
         nKeyNumber = rmsoKeyInfo.nKeyNumber,
         strEncryptedPrivateKey = rmsoKeyInfo.strEncryptedPrivateKey
     });
 }
Exemplo n.º 3
0
        protected virtual byte[] DecryptPrivateKey(KeyInformation keyInfo, SecureString tpdFilePassword)
        {
            IPrivateKeyDecryptor privateKeyDecryptor = this.CreatePrivateKeyDecryptor(tpdFilePassword);

            byte[] result;
            try
            {
                result = privateKeyDecryptor.Decrypt(keyInfo.strEncryptedPrivateKey);
            }
            catch (PrivateKeyDecryptionFailedException e)
            {
                throw new FailedToDecryptPrivateKeyException(e);
            }
            return(result);
        }
Exemplo n.º 4
0
        private TrustedPublishingDomainPrivateKeyProvider CreateKeyProviderAndDkmProtectKey(string tpdName, KeyInformation keyInfo, SecureString tpdFilePassword, out string dkmEncryptedPrivateKey, out object failureTarget)
        {
            failureTarget = null;
            byte[]           bytes            = this.DecryptPrivateKey(keyInfo, tpdFilePassword);
            ExchangeGroupKey exchangeGroupKey = new ExchangeGroupKey(null, "Microsoft Exchange DKM");
            Exception        ex;

            if (!exchangeGroupKey.TryByteArrayToEncryptedString(bytes, out dkmEncryptedPrivateKey, out ex))
            {
                failureTarget = tpdName;
                throw new FailedToDkmProtectPrivateKeyException(ex);
            }
            Dictionary <string, PrivateKeyInformation> dictionary = new Dictionary <string, PrivateKeyInformation>(1, StringComparer.OrdinalIgnoreCase);
            PrivateKeyInformation privateKeyInformation           = new PrivateKeyInformation(keyInfo.strID, keyInfo.strIDType, keyInfo.strKeyContainerName, keyInfo.nKeyNumber, keyInfo.strCSPName, keyInfo.nCSPType, dkmEncryptedPrivateKey, true);

            dictionary.Add(privateKeyInformation.Identity, privateKeyInformation);
            return(new TrustedPublishingDomainPrivateKeyProvider(null, dictionary));
        }
Exemplo n.º 5
0
 private TrustedPublishingDomainPrivateKeyProvider CreatePrivateKeyProvider(string tpdName, KeyInformation keyInfo, SecureString tpdFilePassword, out string dkmEncryptedPrivateKey, out object failureTarget)
 {
     dkmEncryptedPrivateKey = null;
     failureTarget          = null;
     if (!this.refreshTemplatesSwitch && !string.IsNullOrEmpty(keyInfo.strEncryptedPrivateKey))
     {
         return(this.CreateKeyProviderAndDkmProtectKey(tpdName, keyInfo, tpdFilePassword, out dkmEncryptedPrivateKey, out failureTarget));
     }
     return(null);
 }