コード例 #1
0
 public OtherKeyAttribute(
     DerObjectIdentifier	keyAttrId,
     Asn1Encodable		keyAttr)
 {
     this.keyAttrId = keyAttrId;
     this.keyAttr = keyAttr;
 }
コード例 #2
0
 public ContentInfo(
     DerObjectIdentifier	contentType,
     Asn1Encodable		content)
 {
     this.contentType = contentType;
     this.content = content;
 }
コード例 #3
0
 public CertStatus(
     int				tagNo,
     Asn1Encodable	value)
 {
     this.tagNo = tagNo;
     this.value = value;
 }
コード例 #4
0
        public ResponderID(
            X509Name id)
        {
            if (id == null)
                throw new ArgumentNullException("id");

            this.id = id;
        }
コード例 #5
0
 /**
  * @param tagNo the tag number for this object.
  * @param obj the tagged object.
  */
 protected Asn1TaggedObject(
     int             tagNo,
     Asn1Encodable   obj)
 {
     this.explicitly = true;
     this.tagNo = tagNo;
     this.obj = obj;
 }
コード例 #6
0
        public ResponderID(
            Asn1OctetString id)
        {
            if (id == null)
                throw new ArgumentNullException("id");

            this.id = id;
        }
コード例 #7
0
        private ContentInfo(
            Asn1Sequence seq)
        {
            contentType = (DerObjectIdentifier) seq[0];

            if (seq.Count > 1)
            {
                content = ((Asn1TaggedObject) seq[1]).GetObject();
            }
        }
コード例 #8
0
 /**
  * @param explicitly true if the object is explicitly tagged.
  * @param tagNo the tag number for this object.
  * @param obj the tagged object.
  */
 protected Asn1TaggedObject(
     bool            explicitly,
     int             tagNo,
     Asn1Encodable   obj)
 {
     // IAsn1Choice marker interface 'insists' on explicit tagging
     this.explicitly = explicitly || (obj is IAsn1Choice);
     this.tagNo = tagNo;
     this.obj = obj;
 }
コード例 #9
0
 public virtual void WriteObject(
     Asn1Encodable obj)
 {
     if (obj == null)
     {
         WriteNull();
     }
     else
     {
         obj.ToAsn1Object().Encode(this);
     }
 }
コード例 #10
0
 internal Asn1OctetString(
     Asn1Encodable obj)
 {
     try
     {
         this.str = obj.GetEncoded(Asn1Encodable.Der);
     }
     catch (IOException e)
     {
         throw new ArgumentException("Error processing object : " + e.ToString());
     }
 }
コード例 #11
0
        public SmimeCapability(
            DerObjectIdentifier	capabilityID,
            Asn1Encodable		parameters)
        {
            if (capabilityID == null)
                throw new ArgumentNullException("capabilityID");

            this.capabilityID = capabilityID;

            if (parameters != null)
            {
                this.parameters = parameters.ToAsn1Object();
            }
        }
コード例 #12
0
        /**
        * Creates a new <code>CommitmentTypeQualifier</code> instance.
        *
        * @param commitmentTypeIdentifier a <code>CommitmentTypeIdentifier</code> value
        * @param qualifier the qualifier, defined by the above field.
        */
        public CommitmentTypeQualifier(
            DerObjectIdentifier	commitmentTypeIdentifier,
            Asn1Encodable		qualifier)
        {
            if (commitmentTypeIdentifier == null)
                throw new ArgumentNullException("commitmentTypeIdentifier");

            this.commitmentTypeIdentifier = commitmentTypeIdentifier;

            if (qualifier != null)
            {
                this.qualifier = qualifier.ToAsn1Object();
            }
        }
コード例 #13
0
        public CertStatus(
            Asn1TaggedObject choice)
        {
            this.tagNo = choice.TagNo;

            switch (choice.TagNo)
            {
                case 1:
                    value = RevokedInfo.GetInstance(choice, false);
                    break;
                case 0:
                case 2:
                    value = DerNull.Instance;
                    break;
            }
        }
コード例 #14
0
        public ECPrivateKeyStructure(
            BigInteger		key,
            DerBitString	publicKey,
            Asn1Encodable	parameters)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            Asn1EncodableVector v = new Asn1EncodableVector(
                new DerInteger(1),
                new DerOctetString(key.ToByteArrayUnsigned()));

            if (parameters != null)
            {
                v.Add(new DerTaggedObject(true, 0, parameters));
            }

            if (publicKey != null)
            {
                v.Add(new DerTaggedObject(true, 1, publicKey));
            }

            this.seq = new DerSequence(v);
        }
コード例 #15
0
        public DerApplicationSpecific(
            bool			isExplicit,
            int				tag,
            Asn1Encodable	obj)
        {
            Asn1Object asn1Obj = obj.ToAsn1Object();

            byte[] data = asn1Obj.GetDerEncoded();

            this.isConstructed = isExplicit || asn1Obj is Asn1Set || asn1Obj is Asn1Sequence;
            this.tag = tag;

            if (isExplicit)
            {
                this.octets = data;
            }
            else
            {
                int lenBytes = GetLengthOfHeader(data);
                byte[] tmp = new byte[data.Length - lenBytes];
                Array.Copy(data, lenBytes, tmp, 0, tmp.Length);
                this.octets = tmp;
            }
        }
コード例 #16
0
 public RecipientIdentifier(
     Asn1OctetString id)
 {
     this.id = new DerTaggedObject(false, 0, id);
 }
コード例 #17
0
 public RecipientIdentifier(
     Asn1Object id)
 {
     this.id = id;
 }
コード例 #18
0
 private OriginatorIdentifierOrKey(
     Asn1TaggedObject id)
 {
     // TODO Add validation
     this.id = id;
 }
コード例 #19
0
 public RecipientIdentifier(
     IssuerAndSerialNumber id)
 {
     this.id = id;
 }
コード例 #20
0
 public OriginatorIdentifierOrKey(
     OriginatorPublicKey id)
 {
     this.id = new DerTaggedObject(false, 1, id);
 }
コード例 #21
0
 public OriginatorIdentifierOrKey(
     Asn1Object id)
 {
     this.id = id;
 }
コード例 #22
0
 public static ICipherParameters GenerateCipherParameters(
     string          algorithm,
     char[]          password,
     Asn1Encodable   pbeParameters)
 {
     return GenerateCipherParameters(algorithm, password, false, pbeParameters);
 }
コード例 #23
0
        public static ICipherParameters GenerateCipherParameters(
            string          algorithm,
            char[]          password,
            bool			wrongPkcs12Zero,
            Asn1Encodable   pbeParameters)
        {
            string mechanism = (string)algorithms[Platform.ToUpperInvariant(algorithm)];

            byte[] keyBytes = null;
            byte[] salt = null;
            int iterationCount = 0;

            if (IsPkcs12(mechanism))
            {
                Pkcs12PbeParams pbeParams = Pkcs12PbeParams.GetInstance(pbeParameters);
                salt = pbeParams.GetIV();
                iterationCount = pbeParams.Iterations.IntValue;
                keyBytes = PbeParametersGenerator.Pkcs12PasswordToBytes(password, wrongPkcs12Zero);
            }
            else if (IsPkcs5Scheme2(mechanism))
            {
                // See below
            }
            else
            {
                PbeParameter pbeParams = PbeParameter.GetInstance(pbeParameters);
                salt = pbeParams.GetSalt();
                iterationCount = pbeParams.IterationCount.IntValue;
                keyBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password);
            }

            ICipherParameters parameters = null;

            if (IsPkcs5Scheme2(mechanism))
            {
                PbeS2Parameters s2p = PbeS2Parameters.GetInstance(pbeParameters.ToAsn1Object());
                AlgorithmIdentifier encScheme = s2p.EncryptionScheme;
                DerObjectIdentifier encOid = encScheme.ObjectID;
                Asn1Object encParams = encScheme.Parameters.ToAsn1Object();

                // TODO What about s2p.KeyDerivationFunc.ObjectID?
                Pbkdf2Params pbeParams = Pbkdf2Params.GetInstance(s2p.KeyDerivationFunc.Parameters.ToAsn1Object());

                byte[] iv;
                if (encOid.Equals(PkcsObjectIdentifiers.RC2Cbc)) // PKCS5.B.2.3
                {
                    RC2CbcParameter rc2Params = RC2CbcParameter.GetInstance(encParams);
                    iv = rc2Params.GetIV();
                }
                else
                {
                    iv = Asn1OctetString.GetInstance(encParams).GetOctets();
                }

                salt = pbeParams.GetSalt();
                iterationCount = pbeParams.IterationCount.IntValue;
                keyBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password);

                int keyLength = pbeParams.KeyLength != null
                    ?	pbeParams.KeyLength.IntValue * 8
                    :	GeneratorUtilities.GetDefaultKeySize(encOid);

                PbeParametersGenerator gen = MakePbeGenerator(
                    (string)algorithmType[mechanism], null, keyBytes, salt, iterationCount);

                parameters = gen.GenerateDerivedParameters(encOid.Id, keyLength);

                if (iv != null)
                {
                    // FIXME? OpenSSL weirdness with IV of zeros (for ECB keys?)
                    if (Arrays.AreEqual(iv, new byte[iv.Length]))
                    {
                        //Console.Error.Write("***** IV all 0 (length " + iv.Length + ") *****");
                    }
                    else
                    {
                        parameters = new ParametersWithIV(parameters, iv);
                    }
                }
            }
            else if (mechanism.StartsWith("PBEwithSHA-1"))
            {
                PbeParametersGenerator generator = MakePbeGenerator(
                    (string) algorithmType[mechanism], new Sha1Digest(), keyBytes, salt, iterationCount);

                if (mechanism.Equals("PBEwithSHA-1and128bitAES-CBC-BC"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 128, 128);
                }
                else if (mechanism.Equals("PBEwithSHA-1and192bitAES-CBC-BC"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 192, 128);
                }
                else if (mechanism.Equals("PBEwithSHA-1and256bitAES-CBC-BC"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 256, 128);
                }
                else if (mechanism.Equals("PBEwithSHA-1and128bitRC4"))
                {
                    parameters = generator.GenerateDerivedParameters("RC4", 128);
                }
                else if (mechanism.Equals("PBEwithSHA-1and40bitRC4"))
                {
                    parameters = generator.GenerateDerivedParameters("RC4", 40);
                }
                else if (mechanism.Equals("PBEwithSHA-1and3-keyDESEDE-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("DESEDE", 192, 64);
                }
                else if (mechanism.Equals("PBEwithSHA-1and2-keyDESEDE-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("DESEDE", 128, 64);
                }
                else if (mechanism.Equals("PBEwithSHA-1and128bitRC2-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("RC2", 128, 64);
                }
                else if (mechanism.Equals("PBEwithSHA-1and40bitRC2-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("RC2", 40, 64);
                }
                else if (mechanism.Equals("PBEwithSHA-1andDES-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("DES", 64, 64);
                }
                else if (mechanism.Equals("PBEwithSHA-1andRC2-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("RC2", 64, 64);
                }
            }
            else if (mechanism.StartsWith("PBEwithSHA-256"))
            {
                PbeParametersGenerator generator = MakePbeGenerator(
                    (string) algorithmType[mechanism], new Sha256Digest(), keyBytes, salt, iterationCount);

                if (mechanism.Equals("PBEwithSHA-256and128bitAES-CBC-BC"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 128, 128);
                }
                else if (mechanism.Equals("PBEwithSHA-256and192bitAES-CBC-BC"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 192, 128);
                }
                else if (mechanism.Equals("PBEwithSHA-256and256bitAES-CBC-BC"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 256, 128);
                }
            }
            else if (mechanism.StartsWith("PBEwithMD5"))
            {
                PbeParametersGenerator generator = MakePbeGenerator(
                    (string)algorithmType[mechanism], new MD5Digest(), keyBytes, salt, iterationCount);

                if (mechanism.Equals("PBEwithMD5andDES-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("DES", 64, 64);
                }
                else if (mechanism.Equals("PBEwithMD5andRC2-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("RC2", 64, 64);
                }
                else if (mechanism.Equals("PBEwithMD5and128bitAES-CBC-OpenSSL"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 128, 128);
                }
                else if (mechanism.Equals("PBEwithMD5and192bitAES-CBC-OpenSSL"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 192, 128);
                }
                else if (mechanism.Equals("PBEwithMD5and256bitAES-CBC-OpenSSL"))
                {
                    parameters = generator.GenerateDerivedParameters("AES", 256, 128);
                }
            }
            else if (mechanism.StartsWith("PBEwithMD2"))
            {
                PbeParametersGenerator generator = MakePbeGenerator(
                    (string)algorithmType[mechanism], new MD2Digest(), keyBytes, salt, iterationCount);
                if (mechanism.Equals("PBEwithMD2andDES-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("DES", 64, 64);
                }
                else if (mechanism.Equals("PBEwithMD2andRC2-CBC"))
                {
                    parameters = generator.GenerateDerivedParameters("RC2", 64, 64);
                }
            }
            else if (mechanism.StartsWith("PBEwithHmac"))
            {
                string digestName = mechanism.Substring("PBEwithHmac".Length);
                IDigest digest = DigestUtilities.GetDigest(digestName);

                PbeParametersGenerator generator = MakePbeGenerator(
                    (string) algorithmType[mechanism], digest, keyBytes, salt, iterationCount);

                int bitLen = digest.GetDigestSize() * 8;
                parameters = generator.GenerateDerivedMacParameters(bitLen);
            }

            Array.Clear(keyBytes, 0, keyBytes.Length);

            return FixDesParity(mechanism, parameters);
        }
コード例 #24
0
 public override void AddObject(
     Asn1Encodable obj)
 {
     new DerOutputStream(_bOut).WriteObject(obj);
 }
コード例 #25
0
 public SignerIdentifier(
     Asn1OctetString id)
 {
     this.id = new DerTaggedObject(false, 0, id);
 }
コード例 #26
0
 public SignerIdentifier(
     IssuerAndSerialNumber id)
 {
     this.id = id;
 }
コード例 #27
0
 public BerOctetString(
     Asn1Encodable obj)
     : base(obj.ToAsn1Object())
 {
 }
コード例 #28
0
 public OriginatorIdentifierOrKey(
     IssuerAndSerialNumber id)
 {
     this.id = id;
 }
コード例 #29
0
 public SignerIdentifier(
     Asn1Object id)
 {
     this.id = id;
 }
コード例 #30
0
 public OriginatorIdentifierOrKey(
     SubjectKeyIdentifier id)
 {
     this.id = new DerTaggedObject(false, 0, id);
 }