[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection StrongNameK
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection StrongNameKeyPair.cs, 1.2, 1.3 |
Date: |
Wed, 20 Aug 2003 07:48:44 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection
In directory subversions:/tmp/cvs-serv16623/runtime/System/Reflection
Modified Files:
StrongNameKeyPair.cs
Log Message:
Implement the missing TODO's in StrongNameKeyPair.
Index: StrongNameKeyPair.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/StrongNameKeyPair.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** StrongNameKeyPair.cs 20 Dec 2001 10:11:39 -0000 1.2
--- StrongNameKeyPair.cs 20 Aug 2003 11:48:41 -0000 1.3
***************
*** 31,59 ****
{
// Internal state.
! private byte[] key;
// Constructors.
- [TODO]
public StrongNameKeyPair(byte[] keyPairArray)
{
! // TODO
}
- [TODO]
public StrongNameKeyPair(FileStream keyPairFile)
{
! // TODO
}
- [TODO]
public StrongNameKeyPair(String keyPairContainer)
{
! // TODO
}
! // Get the public key.
public byte[] PublicKey
{
get
{
! return key;
}
}
--- 31,134 ----
{
// Internal state.
! private byte[] publicKey;
! private byte[] keyPairArray;
! private String container;
// Constructors.
public StrongNameKeyPair(byte[] keyPairArray)
{
! if(keyPairArray == null)
! {
! throw new
ArgumentNullException("keyPairArray");
! }
! this.keyPairArray =
(byte[])(keyPairArray.Clone());
}
public StrongNameKeyPair(FileStream keyPairFile)
{
! if(keyPairFile == null)
! {
! throw new
ArgumentNullException("keyPairFile");
! }
! int size = (int)(keyPairFile.Length);
! keyPairArray = new byte [size];
! keyPairFile.Read(keyPairArray, 0, size);
}
public StrongNameKeyPair(String keyPairContainer)
{
! if(keyPairContainer == null)
! {
! throw new
ArgumentNullException("keyPairContainer");
! }
! container = keyPairContainer;
! }
!
! // Convert a key pair array into just the public key portion.
! private static byte[] KeyPairToPublicKey(byte[] pair)
! {
! // Validate the header.
! if(pair.Length < 16)
! {
! return null;
! }
! if(pair[0] != 0x07 || // 0x07 indicates a
private key blob.
! pair[1] != 0x02 || // 0x02 is the version
number.
! pair[2] != 0x00 || // Reserved
! pair[3] != 0x00 || // Reserved
! pair[4] != 0x00 || // Algorithm ID: 00 24
00 00
! pair[5] != 0x24 ||
! pair[6] != 0x00 ||
! pair[7] != 0x00 ||
! pair[8] != 0x52 || // Magic: "RSA2"
! pair[9] != 0x53 ||
! pair[10] != 0x41 ||
! pair[11] != 0x32)
! {
! return null;
! }
!
! // Extract the number of bits in the modulus.
! int numBits = pair[12] |
! (pair[13] << 8) |
! (pair[14] << 16) |
! (pair[15] << 24);
! if((numBits % 8) != 0)
! {
! return null;
! }
!
! // Construct the public key array.
! byte[] key = new byte [(numBits / 8) + 32];
! int keySize = key.Length - 12;
!
! // Construct the public key blob.
! key[0] = 0x00; // Algorithm
ID: 00 24 00 00
! key[1] = 0x24;
! key[2] = 0x00;
! key[3] = 0x00;
! key[4] = 0x04; // Hash ID
(SHA1): 04 80 00 00
! key[5] = 0x80;
! key[6] = 0x00;
! key[7] = 0x00;
! key[8] = (byte)(keySize & 0xFF);
! key[9] = (byte)((keySize >> 8) & 0xFF);
! key[10] = (byte)((keySize >> 16) & 0xFF);
! key[11] = (byte)((keySize >> 24) & 0xFF);
! key[12] = 0x06; // 0x06
indicates a public key blob.
! Array.Copy(pair, 1, key, 13, keySize - 1);
! key[23] = 0x31; // "RSA2" ->
"RSA1".
! return key;
}
! // Get the public key portion of the key pair.
public byte[] PublicKey
{
get
{
! if(publicKey == null && keyPairArray !=
null)
! {
! // Extract the public key
portion of the key pair.
! publicKey =
KeyPairToPublicKey(keyPairArray);
! }
! return publicKey;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection StrongNameKeyPair.cs, 1.2, 1.3,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection Assembly.cs, 1.29, 1.30 AssemblyName.cs, 1.4, 1.5
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/runtime Arg.txt, 1.41, 1.42
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection Assembly.cs, 1.29, 1.30 AssemblyName.cs, 1.4, 1.5
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/runtime Arg.txt, 1.41, 1.42
- Index(es):