Inheritance: AsymmetricAlgorithm
Esempio n. 1
0
        public override void SetKey(AsymmetricAlgorithm key)
        {
            if (key == null)
                throw new ArgumentNullException(nameof(key));

            _dsaKey = (DSA)key;
        }
Esempio n. 2
0
        public DSASignatureFormatter(AsymmetricAlgorithm key) : this()
        {
            if (key == null)
                throw new ArgumentNullException(nameof(key));

            _dsaKey = (DSA)key;
        }
Esempio n. 3
0
        internal bool VerifySignature(System.Security.Cryptography.DSA dsa)
        {
            DSASignatureDeformatter deformatter = new DSASignatureDeformatter(dsa);

            deformatter.SetHashAlgorithm("SHA1");
            return(deformatter.VerifySignature(this.Hash, this.Signature));
        }
 public DSASignatureDeformatter(AsymmetricAlgorithm key) : this()
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     this._dsaKey = (DSA) key;
 }
 public override void SetKey(AsymmetricAlgorithm key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     this._dsaKey = (DSA) key;
 }
		public void SetUp () 
		{
			if (rsa == null) {
				rsa = RSA.Create ();
				rsa.ImportParameters (AllTests.GetRsaKey (true));
			}
			if (dsa == null)
				dsa = DSA.Create ();
		}
	public void SetUp () 
	{
		sig = new SignatureDescription();
		// key generation is VERY long so one time is enough
		if (dsa == null)
			dsa = DSA.Create ();
		if (rsa == null)
			rsa = RSA.Create ();
	}
	// Set the key to use to compute the signature.
	public override void SetKey(AsymmetricAlgorithm key)
			{
				if(!(key is DSA))
				{
					throw new CryptographicException
						(_("Crypto_NeedsDSA"));
				}
				keyContainer = (DSA)key;
			}
        /// <summary>
        /// Initializes this instance of an DSA signature algorithm.
        /// </summary>
        /// <param name="dsa">DSA cryptographic service provider to use.</param>
        private void InitializeAlgorithm(System.Security.Cryptography.DSA dsa)
        {
            this.dsa = dsa;

            //Compute the identity.
            DSAParameters parameters = dsa.ExportParameters(false);

            this.identity = new DSAIdentity(parameters);
        }
		public override void SetKey (AsymmetricAlgorithm key)
		{
			if (key != null) {
				// this will throw a InvalidCastException if this isn't
				// a DSA keypair
				dsa = (DSA) key;
			}
			else
				throw new ArgumentNullException ("key");
		}
		public void SetUp () 
		{
			shaSignature [0] = 0x51;
			md5Signature [0] = 0xB4;

			if (rsa == null)
				rsa = RSA.Create ();
			if (dsa == null)
				dsa = DSA.Create ();
		}
Esempio n. 12
0
        /// <summary>
        ///     Create a public key block from a private key.
        /// </summary>
        /// <param name="privateKey">The <see cref="DSA" /> PrivateKey.</param>
        /// <returns>The <see cref="DSACryptoServiceProvider" /> PublicKey.</returns>
        public static DSACryptoServiceProvider make_pubkey(DSA privateKey)
        {
            var publicKey = new DSACryptoServiceProvider(1024);
            publicKey.ImportParameters(privateKey.ExportParameters(false));

            if (!publicKey.PublicOnly)
            {
                publicKey.Dispose();
                throw new Exception("PublicKey contains PrivateKey information, cancelling.");
            }

            return publicKey;
        }
Esempio n. 13
0
		public override void SetKey (AsymmetricAlgorithm key)
		{
			if (key != null) {
				// this will throw a InvalidCastException if this isn't
				// a DSA keypair
				dsa = (DSA) key;
			}
#if NET_2_0
			else
				throw new ArgumentNullException ("key");
#else
			// null is accepted in 1.0/1.1
#endif
		}
 public DSASignatureAlgorithm(System.Security.Cryptography.DSA dsa)
 {
     InitializeAlgorithm(dsa);
 }
Esempio n. 15
0
 internal DSAWrapper(DSA wrapped)
 {
     Debug.Assert(wrapped != null);
     _wrapped = wrapped;
 }
Esempio n. 16
0
		public DSAKeyValue () 
		{
			dsa = (DSA)DSA.Create ();
		}
	// Constructors.
	public DSASignatureFormatter()
			{
				keyContainer = null;
			}
Esempio n. 18
0
 // Constructors.
 public DSASignatureDeformatter()
 {
     keyContainer = null;
 }
Esempio n. 19
0
		public void SetUp ()
		{
#if NET_2_0
			dsa = new NonAbstractDSAForUnitTests ();
#else
			dsa = new DSACryptoServiceProvider ();
#endif
		}
Esempio n. 20
0
 /// <summary>创建用于执行不对称算法的默认加密对象。</summary>
 /// <returns>一个加密对象,用于执行不对称算法。</returns>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
 /// </PermissionSet>
 public static DSA Create()
 {
     return(DSA.Create("System.Security.Cryptography.DSA"));
 }
	public void FixtureSetUp () 
	{
		// key generation is VERY long so one time is enough
		dsa = DSA.Create ();
		rsa = RSA.Create ();
	}
Esempio n. 22
0
		internal bool VerifySignature (DSA dsa) 
		{
			if (signatureOID != "1.2.840.10040.4.3")
				throw new CryptographicException ("Unsupported hash algorithm: " + signatureOID);
			DSASignatureDeformatter v = new DSASignatureDeformatter (dsa);
			// only SHA-1 is supported
			string hashName = "SHA1";
			v.SetHashAlgorithm (hashName);
			ASN1 sign = new ASN1 (signature);
			if ((sign == null) || (sign.Count != 2))
				return false;
			// parts may be less than 20 bytes (i.e. first bytes were 0x00)
			byte[] part1 = sign [0].Value;
			byte[] part2 = sign [1].Value;
			byte[] sig = new byte [40];
			Buffer.BlockCopy (part1, 0, sig, (20 - part1.Length), part1.Length);
			Buffer.BlockCopy (part2, 0, sig, (40 - part2.Length), part2.Length);
			return v.VerifySignature (GetHash (hashName), sig);
		}
Esempio n. 23
0
			static public byte[] Encode (DSA dsa) 
			{
				DSAParameters param = dsa.ExportParameters (true);
				return ASN1Convert.FromUnsignedBigInteger (param.X).GetBytes ();
			}
Esempio n. 24
0
		internal bool VerifySignature (DSA dsa) 
		{
			// signatureOID is check by both this.Hash and this.Signature
			DSASignatureDeformatter v = new DSASignatureDeformatter (dsa);
			// only SHA-1 is supported
			v.SetHashAlgorithm ("SHA1");
			return v.VerifySignature (this.Hash, this.Signature);
		}
 public DSASignatureDeformatter(AsymmetricAlgorithm key) : this() {
     if (key == null) 
         throw new ArgumentNullException("key");
     Contract.EndContractBlock();
     _dsaKey = (DSA) key;
 }
        //
        // public methods
        //

        public override void SetKey(AsymmetricAlgorithm key) {
            if (key == null) 
                throw new ArgumentNullException("key");
            Contract.EndContractBlock();
            _dsaKey = (DSA) key;
        }
Esempio n. 27
0
		static public byte[] ToCapiPublicKeyBlob (DSA dsa)
		{
			DSAParameters p = dsa.ExportParameters (false);
			int keyLength = p.P.Length; // in bytes

			// header + P + Q + G + Y + count + seed
			byte[] blob = new byte [16 + keyLength + 20 + keyLength + keyLength + 4 + 20];

			blob [0] = 0x06;	// Type - PUBLICKEYBLOB (0x06)
			blob [1] = 0x02;	// Version - Always CUR_BLOB_VERSION (0x02)
			// [2], [3]		// RESERVED - Always 0
			blob [5] = 0x22;	// ALGID
			blob [8] = 0x44;	// Magic
			blob [9] = 0x53;
			blob [10] = 0x53;
			blob [11] = 0x31;

			byte[] bitlen = GetBytesLE (keyLength << 3);
			blob [12] = bitlen [0];
			blob [13] = bitlen [1];
			blob [14] = bitlen [2];
			blob [15] = bitlen [3];

			int pos = 16;
			byte[] part;

			part = p.P;
			Array.Reverse (part);
			Buffer.BlockCopy (part, 0, blob, pos, keyLength);
			pos += keyLength;

			part = p.Q;
			Array.Reverse (part);
			Buffer.BlockCopy (part, 0, blob, pos, 20);
			pos += 20;

			part = p.G;
			Array.Reverse (part);
			Buffer.BlockCopy (part, 0, blob, pos, keyLength);
			pos += keyLength;

			part = p.Y;
			Array.Reverse (part);
			Buffer.BlockCopy (part, 0, blob, pos, keyLength);
			pos += keyLength;

			Buffer.BlockCopy (GetBytesLE (p.Counter), 0, blob, pos, 4);
			pos += 4;

			part = p.Seed;
			Array.Reverse (part);
			Buffer.BlockCopy (part, 0, blob, pos, 20);

			return blob;
		}
Esempio n. 28
0
		static public byte[] ToCapiKeyBlob (DSA dsa, bool includePrivateKey)
		{
			if (dsa == null)
				throw new ArgumentNullException ("dsa");

			if (includePrivateKey)
				return ToCapiPrivateKeyBlob (dsa);
			else
				return ToCapiPublicKeyBlob (dsa);
		}
Esempio n. 29
0
        //
        // public constructors
        //

        public DSAKeyValue () {
            m_key = DSA.Create();
        }
Esempio n. 30
0
 public DSAKeyValue (DSA key) {
     m_key = key;
 }
Esempio n. 31
0
		public static AsymmetricCipherKeyPair GetDsaKeyPair(
			DSA dsa)
		{
			return GetDsaKeyPair(dsa.ExportParameters(true));
		}
Esempio n. 32
0
		public static DsaPublicKeyParameters GetDsaPublicKey(
			DSA dsa)
		{
			return GetDsaPublicKey(dsa.ExportParameters(false));
		}
        /************************* PUBLIC METHODS *************************/

        /// <include file='doc\DSASignatureFormatter.uex' path='docs/doc[@for="DSASignatureFormatter.SetKey"]/*' />
        public override void SetKey(AsymmetricAlgorithm key)
        {
            _dsaKey = (DSA)key;
        }
 public DSACryptoServiceProvider() : base()
 {
     // This class wraps DSA
     _impl   = DSA.Create();
     KeySize = 1024;
 }
Esempio n. 35
0
		public virtual byte[] Sign (DSA key) 
		{
			string oid = "1.2.840.10040.4.3";
			ASN1 tbs = ToBeSigned (oid);
			HashAlgorithm ha = HashAlgorithm.Create (hashName);
			if (!(ha is SHA1))
				throw new NotSupportedException ("Only SHA-1 is supported for DSA");
			byte[] hash = ha.ComputeHash (tbs.GetBytes ());

			DSASignatureFormatter dsa = new DSASignatureFormatter (key);
			dsa.SetHashAlgorithm (hashName);
			byte[] rs = dsa.CreateSignature (hash);

			// split R and S
			byte[] r = new byte [20];
			Buffer.BlockCopy (rs, 0, r, 0, 20);
			byte[] s = new byte [20];
			Buffer.BlockCopy (rs, 20, s, 0, 20);
			ASN1 signature = new ASN1 (0x30);
			signature.Add (new ASN1 (0x02, r));
			signature.Add (new ASN1 (0x02, s));

			// dsaWithSha1 (1 2 840 10040 4 3)
			return Build (tbs, oid, signature.GetBytes ());
		}
	public DSASignatureDeformatterTest () 
	{
		// key generation is VERY long so one time is enough
		dsa = DSA.Create ();
		rsa = RSA.Create ();
	}
Esempio n. 37
-1
		internal bool VerifySignature (DSA dsa) 
		{
			if (signatureOID != "1.2.840.10040.4.3")
				throw new CryptographicException ("Unsupported hash algorithm: " + signatureOID);
			DSASignatureDeformatter v = new DSASignatureDeformatter (dsa);
			// only SHA-1 is supported
			v.SetHashAlgorithm ("SHA1");
			ASN1 sign = new ASN1 (signature);
			if ((sign == null) || (sign.Count != 2))
				return false;
			// parts may be less than 20 bytes (i.e. first bytes were 0x00)
			byte[] part1 = sign [0].Value;
			byte[] part2 = sign [1].Value;
			byte[] sig = new byte [40];
			// parts may be less than 20 bytes (i.e. first bytes were 0x00)
			// parts may be more than 20 bytes (i.e. first byte > 0x80, negative)
			int s1 = System.Math.Max (0, part1.Length - 20);
			int e1 = System.Math.Max (0, 20 - part1.Length);
			Buffer.BlockCopy (part1, s1, sig, e1, part1.Length - s1);
			int s2 = System.Math.Max (0, part2.Length - 20);
			int e2 = System.Math.Max (20, 40 - part2.Length);
			Buffer.BlockCopy (part2, s2, sig, e2, part2.Length - s2);
			return v.VerifySignature (Hash, sig);
		}
Esempio n. 38
-1
		public DSAKeyValue (DSA key) 
		{
			dsa = key;
		}