// (C) 2004 Novell (http://www.novell.com)
//
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
{
}
+ public StrongName (int keySize)
+ {
+ rsa = new RSAManaged (keySize);
+ }
+
public StrongName (byte[] data)
{
if (data == null)
get {
if (rsa == null)
return false;
-#if INSIDE_CORLIB
+#if INSIDE_CORLIB && !MOONLIGHT
// the easy way
if (RSA is RSACryptoServiceProvider) {
// available as internal for corlib
public byte[] PublicKey {
get {
if (publicKey == null) {
- byte[] keyPair = CryptoConvert.ToCapiKeyBlob (rsa, false);
- publicKey = new byte [32 + 128]; // always 1024 bits
+ byte[] keyPair = CryptoConvert.ToCapiKeyBlob (rsa, false);
+ // since 2.0 public keys can vary from 384 to 16384 bits
+ publicKey = new byte [32 + (rsa.KeySize >> 3)];
// The first 12 bytes are documented at:
// http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp
byte[] publicKey = PublicKey;
if (publicKey == null)
return null;
- HashAlgorithm ha = SHA1.Create (TokenAlgorithm);
+ HashAlgorithm ha = HashAlgorithm.Create (TokenAlgorithm);
byte[] hash = ha.ComputeHash (publicKey);
// we need the last 8 bytes in reverse order
keyToken = new byte [8];
public bool Verify (string fileName)
{
- StrongNameSignature sn;
+ bool result = false;
using (FileStream fs = File.OpenRead (fileName)) {
- sn = StrongHash (fs, StrongNameOptions.Signature);
+ result = Verify (fs);
fs.Close ();
}
+ return result;
+ }
+
+ public bool Verify (Stream stream)
+ {
+ StrongNameSignature sn = StrongHash (stream, StrongNameOptions.Signature);
if (sn.Hash == null) {
return false;
}
if (!initialized) {
lock (lockObject) {
if (!initialized) {
+#if NET_2_1
+ // Moonlight cannot depend on machine.config
+#else
string config = Environment.GetMachineConfigPath ();
StrongNameManager.LoadConfig (config);
+#endif
initialized = true;
}
}