| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Xml; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.IdentityModel |
| | | 8 | | { |
| | | 9 | | internal class CipherDataElement |
| | | 10 | | { |
| | | 11 | | private byte[] _iv; |
| | | 12 | | private byte[] _cipherText; |
| | | 13 | | |
| | | 14 | | public byte[] CipherValue |
| | | 15 | | { |
| | | 16 | | get |
| | | 17 | | { |
| | 0 | 18 | | if ( _iv != null ) |
| | | 19 | | { |
| | 0 | 20 | | byte[] buffer = new byte[_iv.Length + _cipherText.Length]; |
| | 0 | 21 | | Buffer.BlockCopy( _iv, 0, buffer, 0, _iv.Length ); |
| | 0 | 22 | | Buffer.BlockCopy( _cipherText, 0, buffer, _iv.Length, _cipherText.Length ); |
| | 0 | 23 | | _iv = null; |
| | | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | return _cipherText; |
| | | 27 | | } |
| | | 28 | | set |
| | | 29 | | { |
| | 0 | 30 | | _cipherText = value; |
| | 0 | 31 | | } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public void ReadXml( XmlDictionaryReader reader ) |
| | | 35 | | { |
| | 0 | 36 | | if ( reader == null ) |
| | | 37 | | { |
| | 0 | 38 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 39 | | } |
| | | 40 | | |
| | 0 | 41 | | reader.MoveToContent(); |
| | 0 | 42 | | if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace ) |
| | | 43 | | { |
| | 0 | 44 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml( reader, SR.Format( SR.ID4188 ) ); |
| | | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace ); |
| | 0 | 48 | | reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherValue, XmlEncryptionConstants.Namespace ); |
| | | 49 | | |
| | 0 | 50 | | _cipherText = reader.ReadContentAsBase64(); |
| | 0 | 51 | | _iv = null; |
| | | 52 | | |
| | | 53 | | // <CipherValue> |
| | 0 | 54 | | reader.MoveToContent(); |
| | 0 | 55 | | reader.ReadEndElement(); |
| | | 56 | | |
| | | 57 | | |
| | | 58 | | // <CipherData> |
| | 0 | 59 | | reader.MoveToContent(); |
| | 0 | 60 | | reader.ReadEndElement(); |
| | 0 | 61 | | } |
| | | 62 | | |
| | | 63 | | public void SetCipherValueFragments( byte[] iv, byte[] cipherText ) |
| | | 64 | | { |
| | 0 | 65 | | _iv = iv; |
| | 0 | 66 | | _cipherText = cipherText; |
| | 0 | 67 | | } |
| | | 68 | | |
| | | 69 | | public void WriteXml( XmlWriter writer ) |
| | | 70 | | { |
| | 0 | 71 | | writer.WriteStartElement( XmlEncryptionConstants.Prefix, XmlEncryptionConstants.Elements.CipherData, XmlEncr |
| | 0 | 72 | | writer.WriteStartElement( XmlEncryptionConstants.Prefix, XmlEncryptionConstants.Elements.CipherValue, XmlEnc |
| | | 73 | | |
| | 0 | 74 | | if ( _iv != null ) |
| | 0 | 75 | | writer.WriteBase64( _iv, 0, _iv.Length ); |
| | | 76 | | |
| | 0 | 77 | | writer.WriteBase64( _cipherText, 0, _cipherText.Length ); |
| | | 78 | | |
| | 0 | 79 | | writer.WriteEndElement(); // CipherValue |
| | 0 | 80 | | writer.WriteEndElement(); // CipherData |
| | 0 | 81 | | } |
| | | 82 | | } |
| | | 83 | | } |