Inheritance: System.Security.Cryptography.AsnEncodedData
コード例 #1
0
 public static void Pkcs9AttributeCopyFromAsnNotAPkcs9Attribute()
 {
     // Pkcs9AttributeObject.CopyFrom(AsnEncodedData) refuses to accept any AsnEncodedData that isn't a Pkcs9AttributeObject-derived class. 
     Pkcs9AttributeObject p = new Pkcs9AttributeObject();
     byte[] rawData = "041e4d00790020004400650073006300720069007000740069006f006e000000".HexToByteArray();
     AsnEncodedData a = new AsnEncodedData(Oids.DocumentName, rawData);
     Assert.Throws<ArgumentException>(() => p.CopyFrom(a));
 }
コード例 #2
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorOidArray () 
		{
			Oid o = new Oid (defaultOid);
			Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
			Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
			Assert.AreEqual (0, a.RawData.Length, "RawData");
		}
コード例 #3
0
        public static void Pkcs9AttributeAsnEncodedDataCtorEmptyOidValue()
        {
            Oid oid = new Oid(Oids.Aes128);
            oid.Value = string.Empty;

            AsnEncodedData a = new AsnEncodedData(oid, new byte[3]);
            object ign;
            Assert.Throws<ArgumentException>(() => ign = new Pkcs9AttributeObject(a));
        }
コード例 #4
0
ファイル: Pkcs9Attribute.cs プロジェクト: dox0/DotNet471RS3
        public override void CopyFrom(AsnEncodedData asnEncodedData)
        {
            if (asnEncodedData == null)
            {
                throw new ArgumentNullException("asnEncodedData");
            }
            Pkcs9AttributeObject att = asnEncodedData as Pkcs9AttributeObject;

            if (att == null)
            {
                throw new ArgumentException(SecurityResources.GetResourceString("Cryptography_Pkcs9_AttributeMismatch"));
            }
            base.CopyFrom(asnEncodedData);
        }
コード例 #5
0
        internal static AsnEncodedDataCollection GetAsnEncodedDataCollection(System.Security.Cryptography.CAPI.CRYPT_ATTRIBUTE cryptAttribute)
        {
            AsnEncodedDataCollection datas = new AsnEncodedDataCollection();
            Oid    oid  = new Oid(cryptAttribute.pszObjId);
            string name = oid.Value;

            for (uint i = 0; i < cryptAttribute.cValue; i++)
            {
                IntPtr pBlob = new IntPtr(((long)cryptAttribute.rgValue) + (i * Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB))));
                Pkcs9AttributeObject asnEncodedData = new Pkcs9AttributeObject(oid, System.Security.Cryptography.CAPI.BlobToByteArray(pBlob));
                Pkcs9AttributeObject obj3           = CryptoConfig.CreateFromName(name) as Pkcs9AttributeObject;
                if (obj3 != null)
                {
                    obj3.CopyFrom(asnEncodedData);
                    asnEncodedData = obj3;
                }
                datas.Add(asnEncodedData);
            }
            return(datas);
        }
コード例 #6
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorOidArrayNull ()
		{
			Oid o = new Oid (defaultOid);
			Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, null);
		}
コード例 #7
0
        public static void MessageDigestFromRawData()
        {
            byte[] messageDigest = { 3, 45, 88, 128, 93 };
            List<byte> encodedMessageDigestList = new List<byte>(messageDigest.Length + 2);
            encodedMessageDigestList.Add(4);
            encodedMessageDigestList.Add(checked((byte)(messageDigest.Length)));
            encodedMessageDigestList.AddRange(messageDigest);
            byte[] encodedMessageDigest = encodedMessageDigestList.ToArray();

            Pkcs9MessageDigest p = new Pkcs9MessageDigest();
            Pkcs9AttributeObject pAttribute = new Pkcs9AttributeObject(s_OidMessageDigest, encodedMessageDigest);
            p.CopyFrom(pAttribute);
            Assert.Equal<byte>(encodedMessageDigest, p.RawData);
            Assert.Equal<byte>(messageDigest, p.MessageDigest);
            string oid = p.Oid.Value;
            Assert.Equal(s_OidMessageDigest, oid);
        }
コード例 #8
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorOidNullArray ()
		{
			Oid o = null;
			Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
		}
コード例 #9
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorEmpty () 
		{
			Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
			Assert.IsNull (a.Oid, "Oid");
			Assert.IsNull (a.RawData, "RawData");
		}
コード例 #10
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorAsnEncodedDataNull () 
		{
			Pkcs9AttributeObject a = new Pkcs9AttributeObject (null);
		}
コード例 #11
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void CopyFrom_SigningTime_OidRaw ()
		{
			Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
			Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
			a.CopyFrom (new AsnEncodedData (st.Oid, st.RawData));
		}
コード例 #12
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void CopyFrom_Self ()
		{
			Pkcs9AttributeObject a = new Pkcs9AttributeObject ("1.2.3.4", new byte[2] { 0x05, 0x00 } );
			a.CopyFrom (new AsnEncodedData (a.Oid, a.RawData));
		}
コード例 #13
0
        public static void TestUnprotectedAttributes1_MessageDigest_RoundTrip()
        {
            byte[] rawData = "0405032d58805d".HexToByteArray();
            Pkcs9AttributeObject pkcs9MessageDigest = new Pkcs9AttributeObject(Oids.MessageDigest, rawData);

            byte[] encodedMessage = CreateEcmsWithAttributes(pkcs9MessageDigest);
            VerifyUnprotectedAttributes1_MessageDigest(encodedMessage);
        }
コード例 #14
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorStringArrayNull ()
		{
			Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, null);
		}
コード例 #15
0
ファイル: Pkcs9AttributeTest.cs プロジェクト: nlhepler/mono
		public void ConstructorStringNullArray ()
		{
			string s = null;
			Pkcs9AttributeObject a = new Pkcs9AttributeObject (s, new byte[0]);
		}
コード例 #16
0
 public static void Pkcs9AttributeObjectNullaryCtor()
 {
     Pkcs9AttributeObject p = new Pkcs9AttributeObject();
     Assert.Null(p.Oid);
     Assert.Null(p.RawData);
 }
コード例 #17
0
 internal static AsnEncodedDataCollection GetAsnEncodedDataCollection(System.Security.Cryptography.CAPI.CRYPT_ATTRIBUTE cryptAttribute)
 {
     AsnEncodedDataCollection datas = new AsnEncodedDataCollection();
     Oid oid = new Oid(cryptAttribute.pszObjId);
     string name = oid.Value;
     for (uint i = 0; i < cryptAttribute.cValue; i++)
     {
         IntPtr pBlob = new IntPtr(((long) cryptAttribute.rgValue) + (i * Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB))));
         Pkcs9AttributeObject asnEncodedData = new Pkcs9AttributeObject(oid, System.Security.Cryptography.CAPI.BlobToByteArray(pBlob));
         Pkcs9AttributeObject obj3 = CryptoConfig.CreateFromName(name) as Pkcs9AttributeObject;
         if (obj3 != null)
         {
             obj3.CopyFrom(asnEncodedData);
             asnEncodedData = obj3;
         }
         datas.Add(asnEncodedData);
     }
     return datas;
 }
コード例 #18
0
ファイル: PkcsUtils.cs プロジェクト: JianwenSun/cc
        internal static AsnEncodedDataCollection GetAsnEncodedDataCollection (CAPI.CRYPT_ATTRIBUTE cryptAttribute) {
            AsnEncodedDataCollection list = new AsnEncodedDataCollection();
            Oid oid = new Oid(cryptAttribute.pszObjId);
            string szOid = oid.Value;

            for (uint index = 0; index < cryptAttribute.cValue; index++) {
                checked {
                    IntPtr pAttributeBlob = new IntPtr((long)cryptAttribute.rgValue + (index * Marshal.SizeOf(typeof(CAPI.CRYPTOAPI_BLOB))));
                    Pkcs9AttributeObject attribute = new Pkcs9AttributeObject(oid, CAPI.BlobToByteArray(pAttributeBlob));
                    Pkcs9AttributeObject customAttribute = CryptoConfig.CreateFromName(szOid) as Pkcs9AttributeObject;
                    if (customAttribute != null) {
                        customAttribute.CopyFrom(attribute);
                        attribute = customAttribute;
                    }
                    list.Add(attribute);
                }
            }
            return list;
        }
コード例 #19
0
 private static Pkcs9ContentType CreatePkcs9ContentType(byte[] rawData)
 {
     Pkcs9ContentType pkcs9ContentType = new Pkcs9ContentType();
     Pkcs9AttributeObject pkcs9AttributeObject = new Pkcs9AttributeObject(pkcs9ContentType.Oid, rawData);
     pkcs9ContentType.CopyFrom(pkcs9AttributeObject);
     return pkcs9ContentType;
 }
コード例 #20
0
 public static void Pkcs9AttributeCopyFromNullAsn()
 {
     Pkcs9AttributeObject p = new Pkcs9AttributeObject();
     Assert.Throws<ArgumentNullException>(() => p.CopyFrom(null));
 }
コード例 #21
0
 public static void Pkcs9AttributeAsnEncodedDataCtorNullOid()
 {
     AsnEncodedData a = new AsnEncodedData(new byte[3]);
     object ign;
     Assert.Throws<ArgumentNullException>(() => ign = new Pkcs9AttributeObject(a));
 }
コード例 #22
0
        public static void TestUnprotectedAttributes1_ContentType_RoundTrip()
        {
            byte[] rawData = "06072a9fa20082f300".HexToByteArray();
            Pkcs9AttributeObject pkcs9ContentType = new Pkcs9AttributeObject(Oids.ContentType, rawData);

            byte[] encodedMessage = CreateEcmsWithAttributes(pkcs9ContentType);
            VerifyUnprotectedAttributes1_ContentType(encodedMessage);
        }
コード例 #23
0
        public static void ContentTypeFromCookedData()
        {
            string contentType = "1.3.8473.23.4773.23";
            byte[] encodedContentType = "06072bc21917a52517".HexToByteArray();
            Pkcs9ContentType p = new Pkcs9ContentType();
            Pkcs9AttributeObject pkcs9AttributeObject = new Pkcs9AttributeObject(p.Oid, encodedContentType);
            p.CopyFrom(pkcs9AttributeObject);

            string cookedData = p.ContentType.Value;
            Assert.Equal(contentType, cookedData);
            string oid = p.Oid.Value;
            Assert.Equal(s_OidContentType, oid);
        }