protected override byte[] DecryptSecurityHeaderElement( EncryptedData encryptedData, WrappedKeySecurityToken wrappedKeyToken, out SecurityToken encryptionToken) { if ((encryptedData.KeyIdentifier != null) || (wrappedKeyToken == null)) { // The EncryptedData might have a KeyInfo inside it. Try resolving the SecurityKeyIdentifier. encryptionToken = ResolveKeyIdentifier(encryptedData.KeyIdentifier, this.CombinedPrimaryTokenResolver, false); if (wrappedKeyToken != null && wrappedKeyToken.ReferenceList != null && encryptedData.HasId && wrappedKeyToken.ReferenceList.ContainsReferredId(encryptedData.Id) && (wrappedKeyToken != encryptionToken)) { // We have a EncryptedKey with a ReferenceList inside it. This would mean that // all the EncryptedData pointed by the ReferenceList should be encrypted only // by this key. The individual EncryptedData elements if containing a KeyInfo // clause should point back to the same EncryptedKey token. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.EncryptedKeyWasNotEncryptedWithTheRequiredEncryptingToken, wrappedKeyToken))); } } else { encryptionToken = wrappedKeyToken; } using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(encryptionToken, encryptedData.EncryptionMethod, this.AlgorithmSuite)) { encryptedData.SetUpDecryption(algorithm); return(encryptedData.GetDecryptedBuffer()); } }
protected override byte[] DecryptSecurityHeaderElement(EncryptedData encryptedData, WrappedKeySecurityToken wrappedKeyToken, out SecurityToken encryptionToken) { if ((encryptedData.KeyIdentifier != null) || (wrappedKeyToken == null)) { encryptionToken = ResolveKeyIdentifier(encryptedData.KeyIdentifier, base.CombinedPrimaryTokenResolver, false); if ((((wrappedKeyToken != null) && (wrappedKeyToken.ReferenceList != null)) && (encryptedData.HasId && wrappedKeyToken.ReferenceList.ContainsReferredId(encryptedData.Id))) && (wrappedKeyToken != encryptionToken)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("EncryptedKeyWasNotEncryptedWithTheRequiredEncryptingToken", new object[] { wrappedKeyToken }))); } } else { encryptionToken = wrappedKeyToken; } using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(encryptionToken, encryptedData.EncryptionMethod, base.AlgorithmSuite)) { encryptedData.SetUpDecryption(algorithm); return(encryptedData.GetDecryptedBuffer()); } }
void DecryptBody(XmlDictionaryReader bodyContentReader, SecurityToken token) { EncryptedData bodyXml = new EncryptedData(); bodyXml.ShouldReadXmlReferenceKeyInfoClause = this.MessageDirection == MessageDirection.Output; bodyXml.SecurityTokenSerializer = this.StandardsManager.SecurityTokenSerializer; bodyXml.ReadFrom(bodyContentReader, MaxReceivedMessageSize); if (!bodyContentReader.EOF && bodyContentReader.NodeType != XmlNodeType.EndElement) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.GetString(SR.BadEncryptedBody))); } if (token == null) { token = ResolveKeyIdentifier(bodyXml.KeyIdentifier, this.PrimaryTokenResolver, false); } RecordEncryptionToken(token); using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(token, bodyXml.EncryptionMethod, this.AlgorithmSuite)) { bodyXml.SetUpDecryption(algorithm); this.SecurityVerifiedMessage.SetDecryptedBody(bodyXml.GetDecryptedBuffer()); } }
private void DecryptBody(XmlDictionaryReader bodyContentReader, SecurityToken token) { EncryptedData data = new EncryptedData { SecurityTokenSerializer = base.StandardsManager.SecurityTokenSerializer }; data.ReadFrom(bodyContentReader, base.MaxReceivedMessageSize); if (!bodyContentReader.EOF && (bodyContentReader.NodeType != XmlNodeType.EndElement)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.ServiceModel.SR.GetString("BadEncryptedBody"))); } if (token == null) { token = ResolveKeyIdentifier(data.KeyIdentifier, base.PrimaryTokenResolver, false); } base.RecordEncryptionToken(token); using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(token, data.EncryptionMethod, base.AlgorithmSuite)) { data.SetUpDecryption(algorithm); base.SecurityVerifiedMessage.SetDecryptedBody(data.GetDecryptedBuffer()); } }
private void DecryptBody(XmlDictionaryReader bodyContentReader, SecurityToken token) { EncryptedData data = new EncryptedData { SecurityTokenSerializer = base.StandardsManager.SecurityTokenSerializer }; data.ReadFrom(bodyContentReader, base.MaxReceivedMessageSize); if (!bodyContentReader.EOF && (bodyContentReader.NodeType != XmlNodeType.EndElement)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.ServiceModel.SR.GetString("BadEncryptedBody"))); } if (token == null) { token = ResolveKeyIdentifier(data.KeyIdentifier, base.PrimaryTokenResolver, false); } base.RecordEncryptionToken(token); using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(token, data.EncryptionMethod, base.AlgorithmSuite)) { data.SetUpDecryption(algorithm); base.SecurityVerifiedMessage.SetDecryptedBody(data.GetDecryptedBuffer()); } }
void DecryptBody(XmlDictionaryReader bodyContentReader, SecurityToken token) { EncryptedData bodyXml = new EncryptedData(); bodyXml.ShouldReadXmlReferenceKeyInfoClause = this.MessageDirection == MessageDirection.Output; bodyXml.SecurityTokenSerializer = this.StandardsManager.SecurityTokenSerializer; bodyXml.ReadFrom(bodyContentReader, MaxReceivedMessageSize); if (!bodyContentReader.EOF && bodyContentReader.NodeType != XmlNodeType.EndElement) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.GetString(SR.BadEncryptedBody))); } if (token == null) { token = ResolveKeyIdentifier(bodyXml.KeyIdentifier, this.PrimaryTokenResolver, false); } RecordEncryptionToken(token); using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(token, bodyXml.EncryptionMethod, this.AlgorithmSuite)) { bodyXml.SetUpDecryption(algorithm); this.SecurityVerifiedMessage.SetDecryptedBody(bodyXml.GetDecryptedBuffer()); } }
protected override byte[] DecryptSecurityHeaderElement( EncryptedData encryptedData, WrappedKeySecurityToken wrappedKeyToken, out SecurityToken encryptionToken) { if ((encryptedData.KeyIdentifier != null) || (wrappedKeyToken == null)) { // The EncryptedData might have a KeyInfo inside it. Try resolving the SecurityKeyIdentifier. encryptionToken = ResolveKeyIdentifier(encryptedData.KeyIdentifier, this.CombinedPrimaryTokenResolver, false); if (wrappedKeyToken != null && wrappedKeyToken.ReferenceList != null && encryptedData.HasId && wrappedKeyToken.ReferenceList.ContainsReferredId(encryptedData.Id) && (wrappedKeyToken != encryptionToken)) { // We have a EncryptedKey with a ReferenceList inside it. This would mean that // all the EncryptedData pointed by the ReferenceList should be encrypted only // by this key. The individual EncryptedData elements if containing a KeyInfo // clause should point back to the same EncryptedKey token. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.EncryptedKeyWasNotEncryptedWithTheRequiredEncryptingToken, wrappedKeyToken))); } } else { encryptionToken = wrappedKeyToken; } using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(encryptionToken, encryptedData.EncryptionMethod, this.AlgorithmSuite)) { encryptedData.SetUpDecryption(algorithm); return encryptedData.GetDecryptedBuffer(); } }
protected override byte[] DecryptSecurityHeaderElement(EncryptedData encryptedData, WrappedKeySecurityToken wrappedKeyToken, out SecurityToken encryptionToken) { if ((encryptedData.KeyIdentifier != null) || (wrappedKeyToken == null)) { encryptionToken = ResolveKeyIdentifier(encryptedData.KeyIdentifier, base.CombinedPrimaryTokenResolver, false); if ((((wrappedKeyToken != null) && (wrappedKeyToken.ReferenceList != null)) && (encryptedData.HasId && wrappedKeyToken.ReferenceList.ContainsReferredId(encryptedData.Id))) && (wrappedKeyToken != encryptionToken)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("EncryptedKeyWasNotEncryptedWithTheRequiredEncryptingToken", new object[] { wrappedKeyToken }))); } } else { encryptionToken = wrappedKeyToken; } using (SymmetricAlgorithm algorithm = CreateDecryptionAlgorithm(encryptionToken, encryptedData.EncryptionMethod, base.AlgorithmSuite)) { encryptedData.SetUpDecryption(algorithm); return encryptedData.GetDecryptedBuffer(); } }
public void SetUpDecryption(SymmetricAlgorithm algorithm) { encryptedData.SetUpDecryption(algorithm); }