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