1 using Microsoft.Runtime.Hosting;
16 private bool _keyPairExported;
18 private byte[] _keyPairArray;
20 private string _keyPairContainer;
22 private byte[] _publicKey;
28 [SecuritySafeCritical]
31 if (_publicKey ==
null)
33 _publicKey = ComputePublicKey();
35 byte[] array =
new byte[_publicKey.Length];
36 Array.
Copy(_publicKey, array, _publicKey.Length);
46 [SecuritySafeCritical]
50 if (keyPairFile ==
null)
54 int num = (int)keyPairFile.
Length;
55 _keyPairArray =
new byte[num];
56 keyPairFile.
Read(_keyPairArray, 0, num);
57 _keyPairExported =
true;
65 [SecuritySafeCritical]
69 if (keyPairArray ==
null)
73 _keyPairArray =
new byte[keyPairArray.Length];
74 Array.
Copy(keyPairArray, _keyPairArray, keyPairArray.Length);
75 _keyPairExported =
true;
83 [SecuritySafeCritical]
87 if (keyPairContainer ==
null)
91 _keyPairContainer = keyPairContainer;
92 _keyPairExported =
false;
98 [SecuritySafeCritical]
102 _keyPairExported = (bool)info.GetValue(
"_keyPairExported", typeof(
bool));
103 _keyPairArray = (
byte[])info.GetValue(
"_keyPairArray", typeof(
byte[]));
104 _keyPairContainer = (string)info.GetValue(
"_keyPairContainer", typeof(
string));
105 _publicKey = (
byte[])info.GetValue(
"_publicKey", typeof(
byte[]));
109 private unsafe
byte[] ComputePublicKey()
111 byte[] result =
null;
120 int pcbPublicKeyBlob = 0;
123 if (!((!_keyPairExported) ? StrongNameHelpers.StrongNameGetPublicKey(_keyPairContainer,
null, 0, out ppbPublicKeyBlob, out pcbPublicKeyBlob) : StrongNameHelpers.StrongNameGetPublicKey(
null, _keyPairArray, _keyPairArray.Length, out ppbPublicKeyBlob, out pcbPublicKeyBlob)))
127 result =
new byte[pcbPublicKeyBlob];
128 Buffer.Memcpy(result, 0, (
byte*)ppbPublicKeyBlob.ToPointer(), 0, pcbPublicKeyBlob);
132 if (ppbPublicKeyBlob != IntPtr.Zero)
134 StrongNameHelpers.StrongNameFreeBuffer(ppbPublicKeyBlob);
148 info.AddValue(
"_keyPairExported", _keyPairExported);
149 info.AddValue(
"_keyPairArray", _keyPairArray);
150 info.AddValue(
"_keyPairContainer", _keyPairContainer);
151 info.AddValue(
"_publicKey", _publicKey);
160 private bool GetKeyPair(out
object arrayOrContainer)
162 arrayOrContainer = (_keyPairExported ? ((object)_keyPairArray) : ((object)_keyPairContainer));
163 return _keyPairExported;
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
Encapsulates access to a public or private key pair used to sign strong name assemblies.
override int Read([In] [Out] byte[] array, int offset, int count)
Reads a block of bytes from the stream and writes the data in a given buffer.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
void OnDeserialization(object sender)
Runs when the entire object graph has been deserialized.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
A platform-specific type that is used to represent a pointer or a handle.
StrongNameKeyPair(FileStream keyPairFile)
Initializes a new instance of the T:System.Reflection.StrongNameKeyPair class, building the key pair ...
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
StrongNameKeyPair(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.Reflection.StrongNameKeyPair class, building the key pair ...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
The exception that is thrown when one of the arguments provided to a method is not valid.
override long Length
Gets the length in bytes of the stream.
StrongNameKeyPair(byte[] keyPairArray)
Initializes a new instance of the T:System.Reflection.StrongNameKeyPair class, building the key pair ...
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Allows an object to control its own serialization and deserialization.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Specifies that the class can be serialized.
SecurityPermissionFlag
Specifies access flags for the security permission object.
byte [] PublicKey
Gets the public part of the public key or public key token of the key pair.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
Provides a set of static methods and properties that provide support for compilers....
StrongNameKeyPair(string keyPairContainer)
Initializes a new instance of the T:System.Reflection.StrongNameKeyPair class, building the key pair ...