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(); } }
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 }); }
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); }
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)); }
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); }