// (C) 2002
// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
// Portions (C) 2003 Ben Maurer
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
+#if !MOONLIGHT
+
using System.IO;
using System.Globalization;
+using System.Runtime.InteropServices;
using Mono.Security.Cryptography;
namespace System.Security.Cryptography {
-#if NET_1_0
- public class DSACryptoServiceProvider : DSA {
-#else
- public sealed class DSACryptoServiceProvider : DSA {
-#endif
+ [ComVisible (true)]
+ public sealed class DSACryptoServiceProvider : DSA, ICspAsymmetricAlgorithm {
private const int PROV_DSS_DH = 13; // from WinCrypt.h
private KeyPairPersistence store;
persistKey = (parameters != null);
if (parameters == null) {
parameters = new CspParameters (PROV_DSS_DH);
-#if ! NET_1_0
+#if NET_1_1
if (useMachineKeyStore)
parameters.Flags |= CspProviderFlags.UseMachineKeyStore;
#endif
get { return dsa.KeySize; }
}
- public override KeySizes[] LegalKeySizes {
- get { return LegalKeySizesValue; }
- }
-
public bool PersistKeyInCsp {
get { return persistKey; }
set { persistKey = value; }
}
-#if (NET_1_0 || NET_1_1)
- internal
-#else
- public
-#endif
- bool PublicOnly {
+ [ComVisible (false)]
+ public bool PublicOnly {
get { return dsa.PublicOnly; }
}
get { return "http://www.w3.org/2000/09/xmldsig#dsa-sha1"; }
}
-#if ! NET_1_0
+#if NET_1_1
private static bool useMachineKeyStore = false;
public static bool UseMachineKeyStore {
return dsa.CreateSignature (rgbHash);
}
- public byte[] SignData (byte[] data)
+ public byte[] SignData (byte[] buffer)
{
// right now only SHA1 is supported by FIPS186-2
HashAlgorithm hash = SHA1.Create ();
- byte[] toBeSigned = hash.ComputeHash (data);
+ byte[] toBeSigned = hash.ComputeHash (buffer);
return dsa.CreateSignature (toBeSigned);
}
- public byte[] SignData (byte[] data, int offset, int count)
+ public byte[] SignData (byte[] buffer, int offset, int count)
{
// right now only SHA1 is supported by FIPS186-2
HashAlgorithm hash = SHA1.Create ();
- byte[] toBeSigned = hash.ComputeHash (data, offset, count);
+ byte[] toBeSigned = hash.ComputeHash (buffer, offset, count);
return dsa.CreateSignature (toBeSigned);
}
persisted = true;
}
}
+ // ICspAsymmetricAlgorithm
+
+ [MonoTODO ("call into KeyPairPersistence to get details")]
+ [ComVisible (false)]
+ public CspKeyContainerInfo CspKeyContainerInfo {
+ get { return null; }
+ }
+
+ [ComVisible (false)]
+ public byte[] ExportCspBlob (bool includePrivateParameters)
+ {
+ byte[] blob = null;
+ if (includePrivateParameters)
+ blob = CryptoConvert.ToCapiPrivateKeyBlob (this);
+ else
+ blob = CryptoConvert.ToCapiPublicKeyBlob (this);
+ return blob;
+ }
+
+ [ComVisible (false)]
+ public void ImportCspBlob (byte[] keyBlob)
+ {
+ if (keyBlob == null)
+ throw new ArgumentNullException ("keyBlob");
+ DSA dsa = CryptoConvert.FromCapiKeyBlobDSA (keyBlob);
+ if (dsa is DSACryptoServiceProvider) {
+ DSAParameters dsap = dsa.ExportParameters (!(dsa as DSACryptoServiceProvider).PublicOnly);
+ ImportParameters (dsap);
+ } else {
+ // we can't know from DSA if the private key is available
+ try {
+ // so we try it...
+ DSAParameters dsap = dsa.ExportParameters (true);
+ ImportParameters (dsap);
+ }
+ catch {
+ // and fall back
+ DSAParameters dsap = dsa.ExportParameters (false);
+ ImportParameters (dsap);
+ }
+ }
+ }
}
}
+
+#endif
+