Esempio n. 1
0
        // Convert an ASN.1 buffer into DSA public parameters.
        internal void ASN1ToPublic(ASN1Parser parser)
        {
            parser = parser.GetSequence();
            if (parser.Type == ASN1Type.Sequence)
            {
                // This looks like it may be a "SubjectPublicKeyInfo"
                // from an X.509 certificate.  Validate the algorithm ID.
                ASN1Parser alg   = parser.GetSequence();
                byte[]     objid = alg.GetObjectIdentifier();
                if (!ASN1Parser.IsObjectID(objid, dsaID))
                {
                    throw new CryptographicException
                              (_("Crypto_InvalidASN1"));
                }

                // Get the common P, Q, and G parameters.
                ASN1Parser algParams = alg.GetSequence();
                P = algParams.GetBigInt();
                Q = algParams.GetBigInt();
                G = algParams.GetBigInt();
                algParams.AtEnd();
                alg.AtEnd();

                // Get the public key information (Y).
                ASN1Parser bitString = parser.GetBitStringContents();
                Y = bitString.GetBigInt();
                bitString.AtEnd();
                parser.AtEnd();
            }
            else
            {
                // This looks like a bare list of DSA parameters.
                P = parser.GetBigInt();
                Q = parser.GetBigInt();
                G = parser.GetBigInt();
                Y = parser.GetBigInt();
                if (!parser.IsAtEnd())
                {
                    // It looks like we have private DSA parameters also.
                    J       = parser.GetBigInt();
                    X       = parser.GetBigInt();
                    Seed    = parser.GetBigInt();
                    Counter = parser.GetInt32();
                }
                parser.AtEnd();
            }
        }
Esempio n. 2
0
        // Convert an ASN.1 buffer into RSA public parameters.
        internal void ASN1ToPublic(ASN1Parser parser)
        {
            parser = parser.GetSequence();
            if (parser.Type == ASN1Type.Sequence)
            {
                // This looks like it may be a "SubjectPublicKeyInfo"
                // from an X.509 certificate.  Validate the algorithm ID.
                ASN1Parser alg   = parser.GetSequence();
                byte[]     objid = alg.GetObjectIdentifier();
                if (!ASN1Parser.IsObjectID(objid, rsaID))
                {
                    throw new CryptographicException
                              (_("Crypto_InvalidASN1"));
                }
                alg.GetNull();
                alg.AtEnd();

                // Get the public key information.
                ASN1Parser bitString = parser.GetBitStringContents();
                ASN1Parser inner     = bitString.GetSequence();
                Modulus  = inner.GetBigInt();
                Exponent = inner.GetBigInt();
                inner.AtEnd();
                bitString.AtEnd();
                parser.AtEnd();
            }
            else if (parser.Type == ASN1Type.Integer &&
                     parser.Length == 1)
            {
                // This looks like a list of private RSA parameters.
                ASN1ToPrivate(parser);
            }
            else
            {
                // This looks like a bare list of RSA parameters.
                Modulus  = parser.GetBigInt();
                Exponent = parser.GetBigInt();
                parser.AtEnd();
            }
        }
Esempio n. 3
0
 // Convert an ASN.1 buffer into DSA private parameters.
 internal void ASN1ToPrivate(ASN1Parser parser)
 {
     parser  = parser.GetSequence();
     P       = parser.GetBigInt();
     Q       = parser.GetBigInt();
     G       = parser.GetBigInt();
     Y       = parser.GetBigInt();
     J       = parser.GetBigInt();
     X       = parser.GetBigInt();
     Seed    = parser.GetBigInt();
     Counter = parser.GetInt32();
     parser.AtEnd();
 }
Esempio n. 4
0
 // Convert an ASN.1 buffer into RSA private parameters.
 internal void ASN1ToPrivate(ASN1Parser parser)
 {
     parser = parser.GetSequence();
     if (parser.GetInt32() != 0)
     {
         // Incorrect version for RSA private key parameters.
         throw new CryptographicException
                   (_("Crypto_InvalidASN1"));
     }
     Modulus  = parser.GetBigInt();
     Exponent = parser.GetBigInt();
     D        = parser.GetBigInt();
     P        = parser.GetBigInt();
     Q        = parser.GetBigInt();
     DP       = parser.GetBigInt();
     DQ       = parser.GetBigInt();
     InverseQ = parser.GetBigInt();
     parser.AtEnd();
 }
	// Convert an ASN.1 buffer into RSA private parameters.
	internal void ASN1ToPrivate(ASN1Parser parser)
			{
				parser = parser.GetSequence();
				if(parser.GetInt32() != 0)
				{
					// Incorrect version for RSA private key parameters.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				Modulus = parser.GetBigInt();
				Exponent = parser.GetBigInt();
				D = parser.GetBigInt();
				P = parser.GetBigInt();
				Q = parser.GetBigInt();
				DP = parser.GetBigInt();
				DQ = parser.GetBigInt();
				InverseQ = parser.GetBigInt();
				parser.AtEnd();
			}
	// Convert an ASN.1 buffer into RSA public parameters.
	internal void ASN1ToPublic(ASN1Parser parser)
			{
				parser = parser.GetSequence();
				if(parser.Type == ASN1Type.Sequence)
				{
					// This looks like it may be a "SubjectPublicKeyInfo"
					// from an X.509 certificate.  Validate the algorithm ID.
					ASN1Parser alg = parser.GetSequence();
					byte[] objid = alg.GetObjectIdentifier();
					if(!ASN1Parser.IsObjectID(objid, rsaID))
					{
						throw new CryptographicException
							(_("Crypto_InvalidASN1"));
					}
					alg.GetNull();
					alg.AtEnd();

					// Get the public key information.
					ASN1Parser bitString = parser.GetBitStringContents();
					ASN1Parser inner = bitString.GetSequence();
					Modulus = inner.GetBigInt();
					Exponent = inner.GetBigInt();
					inner.AtEnd();
					bitString.AtEnd();
					parser.AtEnd();
				}
				else if(parser.Type == ASN1Type.Integer &&
				        parser.Length == 1)
				{
					// This looks like a list of private RSA parameters.
					ASN1ToPrivate(parser);
				}
				else
				{
					// This looks like a bare list of RSA parameters.
					Modulus = parser.GetBigInt();
					Exponent = parser.GetBigInt();
					parser.AtEnd();
				}
			}
	// Convert an ASN.1 buffer into DSA private parameters.
	internal void ASN1ToPrivate(ASN1Parser parser)
			{
				parser = parser.GetSequence();
				P = parser.GetBigInt();
				Q = parser.GetBigInt();
				G = parser.GetBigInt();
				Y = parser.GetBigInt();
				J = parser.GetBigInt();
				X = parser.GetBigInt();
				Seed = parser.GetBigInt();
				Counter = parser.GetInt32();
				parser.AtEnd();
			}
	// Convert an ASN.1 buffer into DSA public parameters.
	internal void ASN1ToPublic(ASN1Parser parser)
			{
				parser = parser.GetSequence();
				if(parser.Type == ASN1Type.Sequence)
				{
					// This looks like it may be a "SubjectPublicKeyInfo"
					// from an X.509 certificate.  Validate the algorithm ID.
					ASN1Parser alg = parser.GetSequence();
					byte[] objid = alg.GetObjectIdentifier();
					if(!ASN1Parser.IsObjectID(objid, dsaID))
					{
						throw new CryptographicException
							(_("Crypto_InvalidASN1"));
					}

					// Get the common P, Q, and G parameters.
					ASN1Parser algParams = alg.GetSequence();
					P = algParams.GetBigInt();
					Q = algParams.GetBigInt();
					G = algParams.GetBigInt();
					algParams.AtEnd();
					alg.AtEnd();

					// Get the public key information (Y).
					ASN1Parser bitString = parser.GetBitStringContents();
					Y = bitString.GetBigInt();
					bitString.AtEnd();
					parser.AtEnd();
				}
				else
				{
					// This looks like a bare list of DSA parameters.
					P = parser.GetBigInt();
					Q = parser.GetBigInt();
					G = parser.GetBigInt();
					Y = parser.GetBigInt();
					if(!parser.IsAtEnd())
					{
						// It looks like we have private DSA parameters also.
						J = parser.GetBigInt();
						X = parser.GetBigInt();
						Seed = parser.GetBigInt();
						Counter = parser.GetInt32();
					}
					parser.AtEnd();
				}
			}