Exemple #1
0
 private byte[] getRandomNum(PKCS8.PrivateKeyInfo priKey)
 {
     foreach (ASN1 i in priKey.Attributes)
     {
         Asn1Reader reader = new Asn1Reader(i.GetBytes());
         bool       isRandomNumAttribute = false, inSET = false;
         do
         {
             if (reader.TagName == "OBJECT_IDENTIFIER")
             {
                 if (((Asn1ObjectIdentifier)reader.GetTagObject()).Value.Value == "1.2.410.200004.10.1.1.3")
                 {
                     isRandomNumAttribute = true;
                 }
             }
             else if (reader.TagName == "SET" && isRandomNumAttribute)
             {
                 inSET = true;
             }
             else if (reader.TagName == "BIT_STRING" && inSET)
             {
                 Asn1BitString asn1BitString = new Asn1BitString(reader);
                 return(asn1BitString.Value);
             }
         } while (reader.MoveNext());
     }
     throw new VIDOperationException("RandomNum in private key attributes is missing");
 }
Exemple #2
0
        private void getVIDHash(X509Certificate2 cert, out string name, out string hashAlg, out byte[] hash)
        {
            // ignore warnings
            name    = "";
            hashAlg = "";
            hash    = new byte[] { };
            bool notset_n = true, notset_hal = true, notset_ha = true;

            foreach (var ext in cert.Extensions)
            {
                if (ext.Oid.Value != "2.5.29.17")
                {
                    continue;
                }
                Asn1Reader reader = new Asn1Reader(ext.RawData);
                bool       kisaIdentifyData = false, kisaVid = false; // TO-DO : Caluate Depth
                do
                {
                    switch (reader.TagName)
                    {
                    case "OBJECT_IDENTIFIER":
                        Asn1ObjectIdentifier identifier = (Asn1ObjectIdentifier)reader.GetTagObject();
                        string oid = identifier.Value.Value;
                        if (oid == "1.2.410.200004.10.1.1")
                        {
                            kisaIdentifyData = true;
                        }
                        else if (oid == "1.2.410.200004.10.1.1.1")
                        {
                            kisaVid = true;
                        }
                        else if (kisaVid && notset_hal)
                        {
                            hashAlg    = oid;
                            notset_hal = false;
                        }
                        break;

                    case "UTF8String":
                        if (kisaIdentifyData && notset_n)
                        {
                            name     = Encoding.UTF8.GetString(reader.GetPayload());
                            notset_n = false;
                        }
                        break;

                    case "OCTET_STRING":
                        if (kisaVid && notset_ha)
                        {
                            SysadminsLV.Asn1Parser.Universal.Asn1OctetString octetString = new SysadminsLV.Asn1Parser.Universal.Asn1OctetString(reader);
                            hash      = octetString.Value;
                            notset_ha = false;
                        }
                        break;

                    default:
                        break;
                    }
                } while (reader.MoveNext());
                if (notset_ha || notset_hal || notset_n)
                {
                    throw new VIDOperationException("Some of vid informations in certificate are missing");
                }
            }
        }